The HAVING
clause is optional and eliminates group rows that do not satisfy a given condition. HAVING
is similar to the WHERE
clause, but WHERE
occurs before the grouping, and HAVING
occurs after.
WHERE
clause places conditions on selected columns, whereas the HAVING
clause places conditions on groups created by the GROUP BY
clause.
Here’s an example showing the position of the HAVING
clause in a SELECT query:
HAVING
clause example: