Database
HAVING (CLAUSE)
Added: June 23, 2026
Definition
HAVING is a SQL clause used to filter grouped results after applying GROUP BY, especially on aggregate functions like COUNT(), SUM(), AVG(), etc.
What Problem It Solves
It solves the limitation that WHERE cannot filter aggregate results, so HAVING is used for filtering group-level data.
What Happens If Not Used
You get all grouped results, even those that don’t meet conditions (e.g., all departments shown, not just high-count ones).
Easy Wording
It “filters groups after calculation.”
Technical Example
After counting students in each class, HAVING COUNT > 30 shows only large classes.
SELECT department, COUNT()
FROM employees
GROUP BY department
HAVING COUNT() > 10;
Result: only departments with more than 10 employees.