MicrolearnENPTES

Filtering groups with HAVING

Lesson 12 of 24 · SQL.Micro

WHERE filters rows before grouping; HAVING filters groups after the aggregates are computed.

You cannot use an aggregate inside WHERE. That is what HAVING is for.

Order of a query: SELECT, FROM, WHERE, GROUP BY, HAVING, ORDER BY, LIMIT.

Check yourself

Where do you filter on SUM(quantity) > 10?

Show customer_id and number of orders, only for customers with 2 or more orders.

Do it in the browser: a real SQL tool, a short mission and instant feedback. No install.

Start this lesson — free
← GROUP BYINNER JOIN →

All lessons · SQL.Micro