HAVING: filtering groups
Keep only the groups that pass a test.
Filter the groups
WHERE filters rows before grouping; HAVING filters the groups after aggregation. "Genres with more than two books":
SELECT genre, COUNT(*) AS books
FROM books
GROUP BY genre
HAVING COUNT(*) > 2;
Think of it as WHERE for aggregates. You can use both in one query: WHERE narrows the rows, HAVING narrows the resulting groups.