Free visual guide
SQL WHERE vs HAVING
WHERE filters individual rows before grouping happens. HAVING filters whole groups after. Picture a tray of decorated sugar cookies and a stack of pastel tins.

The three steps
- WHERE sets aside cookies that cost under 4.
- GROUP BY puts the remaining cookies into tins by shape — all the heart cookies together, and all the star cookies together.
- HAVING keeps only tins holding more than one cookie.
Both in one query
SELECT shape, COUNT(*) AS cookies
FROM cookies
WHERE price >= 4
GROUP BY shape
HAVING COUNT(*) > 1;Rule of thumb: if the condition is about one row, use WHERE. If it uses an aggregate like COUNT or SUM, use HAVING.
Want the full example with every starting row? Read the WHERE vs HAVING lesson.
Ready to practice?
Chapter 4 of the Foundations Track is all about filtering groups. Tap tiles, see real results. No terminal, no setup.
practice WHERE & HAVING