Keep only groups that meet aggregate criteria.
Section: aggregation and grouping
Filter grouped results with HAVING
sql
sql
SELECT user_id, COUNT(*) AS order_count
FROM orders
GROUP BY user_id
HAVING COUNT(*) >= 5;Explanation
`HAVING` filters after aggregation, unlike `WHERE`.
Learn the surrounding workflow
Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.
Related commands
Same sheet · prioritizing aggregation and grouping