SQL LEARNING PLATFORM
Filtering groups — the WHERE clause for aggregates.
Learning Blocks
Interactive Queries
Concepts you'll master
Why WHERE cannot be used with aggregate functions
HAVING to filter grouped results
The definitive WHERE vs HAVING comparison
SELECT department, COUNT(*) AS headcount FROM employees GROUP BY department HAVING COUNT(*) > 2;
❌ Common Mistake: Writing WHERE COUNT(*) > 2 throws an error. WHERE runs before aggregation — the COUNT values do not exist yet at that point in execution. Use HAVING.
✅ Interview Tip 'What is the difference between WHERE and HAVING?' is asked in almost every data-related SQL interview. Answer: WHERE filters rows before grouping; HAVING filters groups after aggregation.
Practice your SQL skills