HAVING versus WHERE
WHERE filters rows before grouping. HAVING filters groups after aggregation.
Example
SELECT country, COUNT(*) AS n FROM students
GROUP BY country
HAVING COUNT(*) >= 2;Result
country | n Ghana | 2 Nigeria | 4
Exercise
Filter groups.
GROUP BY country COUNT(*) > 1
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.