Skip
Arish's avatar

159. HAVING Clause


HAVING Clause

Filter groups (like WHERE but for aggregates).

sql
1SELECT course, COUNT(*) AS count
2FROM students
3GROUP BY course
4HAVING COUNT(*) > 3;

Only courses with more than 3 students.

WHERE vs HAVING

  • WHERE: Filters rows before grouping
  • HAVING: Filters groups after grouping