What is Compare HAVING to WHERE
While both HAVING and WHERE clauses filter data, remember that WHERE operates on rows returned by the FROM clause. If a GROUP BY … HAVING section exists in your query following a WHERE clause, the WHERE clause will filter rows before GROUP BY is processed—potentially limiting the groups that can be created.
A HAVING clause is processed after GROUP BY and only operates on groups, not detail rows. To summarize:
- A WHERE clause filters rows before any groups are formed
- A HAVING clause filters entire groups, and usually looks at the results of an aggregation.