Learn SQL Lesson

Filtering Groups with HAVING

`WHERE` filters individual rows before grouping. `HAVING` filters the groups after aggregation.

For example, to find salespeople with more than one sale:

SELECT salesperson, COUNT(*) AS sale_count
FROM sales
GROUP BY salesperson
HAVING COUNT(*) > 1

This is useful when you want to keep only groups that meet an aggregate condition.

Practice challenge

Find salespeople with more than one sale. Return salesperson and sale_count, ordered by salesperson.

Open interactive editor