SQL HAVING
Filters groups after GROUP BY using a condition on an aggregate, e.g. HAVING COUNT(*) > 2. WHERE filters rows before grouping. HAVING comes after GROUP BY.
Understanding SQL HAVING in QCE Digital Solutions Unit 3
What it does: The WHERE condition checks each row's yearLevel and removes rows before GROUP BY builds the groups. The correct order is WHERE, GROUP BY, HAVING, then ORDER BY, so HAVING sits straight after GROUP BY. HAVING applies a condition to the aggregate COUNT(*) after the groups have been formed, so small groups are removed. HAVING can test an aggregate function such as AVG, which WHERE is not able to do.
Common mistakes: The grouping clause is GROUP BY, not GROUP. The line should be GROUP BY house, and HAVING then filters those groups. HAVING filters groups, so the groups must be created first with GROUP BY. The line should be GROUP BY house, not ORDER BY.
Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.
This module's key terms are also in a printable crossword (Modules 251–337) and word search (Modules 194–337).
Take this worksheet further — free with Cloodit
Each concept is reinforced from every angle — learned, then applied, then tested.
Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.
Over 100 of them, across seven natural biomes.
Turns their work into revision material ready for Flash Cards and Exam study.
Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.
Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.
Quick Questions
Match the Pairs
Key Term
HAVINGFill in the Blanks
Spot the Error
Student with a class code? Join your class →