What is the difference between the WHERE and HAVING clauses in SQL?
Correct answer
D. WHERE filters rows before grouping; HAVING filters groups
15 views
D. WHERE filters rows before grouping; HAVING filters groups
15 views
WHERE runs before GROUP BY and removes individual rows, so it cannot reference aggregate functions such as SUM, while HAVING runs after grouping and filters whole groups on aggregate results. A query can use both: WHERE to trim the input and HAVING to keep only groups that meet a threshold. Logically the clauses execute FROM, WHERE, GROUP BY, HAVING, SELECT, ORDER BY in that order.
Asked in: NTS, PPSC IT, Interviews
Not sure why the answer is D? Ask here and get an explanation.