WHERE and HAVING both filter data, but at different stages of query execution — and mixing them up is one of the most common SQL mistakes in interviews and real work alike.
Key Points
- WHERE filters individual rows before any grouping happens
- HAVING filters groups after GROUP BY and aggregation
- Aggregate functions (SUM, COUNT) can appear in HAVING, not in WHERE
- Use both together: WHERE trims rows first, HAVING trims groups after
- WHERE is faster because it reduces data before aggregation
- Example: WHERE year = 2026 … GROUP BY region HAVING SUM(sales) > 100000
.png)