juniorMySQL
WHERE vs HAVING clauses
Updated May 4, 2026
Short answer
WHERE filters rows before grouping; HAVING filters groups after grouping.
Deep explanation
WHERE filters individual rows. HAVING is applied after GROUP BY and can evaluate aggregate functions like SUM() or COUNT().
Real-world example
Finding departments that have more than 5 employees.
Common mistakes
- Trying to use an aggregate function like SUM() in a WHERE clause.
Follow-up questions
- Can HAVING be used without GROUP BY?