Answer the question
In order to leave comments, you need to log in
What is the difference between HAVING and WHERE?
Why can't this selection be rewritten using WHERE ?
SELECT StudentId FROM EXAM_RESULT GROUP BY StudentID HAVING MIN(Mark) = 5
Answer the question
In order to leave comments, you need to log in
From documentation :
The main difference between WHERE and HAVING is that WHERE first selects rows and then groups them and evaluates aggregate functions (so it selects rows to evaluate aggregates), while HAVING selects group rows after grouping and computing aggregate functions. As a consequence, the WHERE clause must not contain aggregate functions; it doesn't make sense to use aggregate functions to define strings to evaluate aggregate functions. The HAVING clause, on the other hand, always contains aggregate functions. (Strictly speaking, you can write a HAVING clause without using aggregates, but this is rarely useful. The same condition can work more efficiently in the WHERE stage.)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question