Filtering Groups with HAVING
WHERE filters individual rows BEFORE grouping. HAVING filters groups AFTER aggregation.
Syntax
SELECT column, AGGREGATE(other_column)
FROM table
GROUP BY column
HAVING condition_on_aggregate;
WHERE vs HAVING
| Clause | When it filters | What it filters |
|---|---|---|
| WHERE | Before grouping | Individual rows |
| HAVING | After grouping | Groups based on aggregate values |
Exercises
Loading exercise...
Loading exercise...
Loading exercise...
Loading exercise...
Loading exercise...
Complete Query Order
SELECT columns
FROM table
WHERE row_conditions
GROUP BY grouping_columns
HAVING group_conditions
ORDER BY sort_columns
LIMIT n;
Loading exercise...
Free Practice
Loading SQL editor...
Up next · Lesson 18 of 27
Introduction to JOINs
1 min read
17 of 27 lessons done

Ask Byte about this lesson
A private chat about this lesson. Byte has read the whole lesson, answers in seconds, and shows the section each answer comes from. Ask follow-ups in any language.
Questions & Answers
Public questions about this lesson. The AI Tutor answers right away in your language, the FreeAcademy team checks answers, and every learner can read them.

