Skip to content
LakeBench
ProblemsCommunityPricing
Sign inStart practicing
Back
  1. Home
  2. Interview prep
  3. WHERE vs HAVING

SQL · Basics & Joins

WHERE vs HAVING

Easysql-02
wherehavingaggregation

Question

What is the difference between WHERE and HAVING?

Solution

WHERE filters rows before grouping.

HAVING filters groups after GROUP BY.

SELECT department, COUNT(*)
FROM employees
WHERE salary > 50000
GROUP BY department
HAVING COUNT(*) > 10;

Rough execution order:

FROM
WHERE
GROUP BY
HAVING
SELECT
ORDER BY

You cannot put aggregates like `COUNT()` in WHERE, because grouping has not happened yet.

🎯 Put this concept into practice

Solidify this answer with real hands-on interview drills in the browser studio.

Open related drill →
PreviousNext