SQL

HAVING Clause

Learn how to filter groups.

By TechCoder TeamLast updated: 2026-06-02
In a Nutshell

Learn how to filter groups. This hands-on tutorial focuses on practical implementation of having clause concepts.

Why HAVING?

The HAVING clause was added to SQL because the WHERE keyword cannot be used with aggregate functions. WHERE filters rows before grouping, while HAVING filters groups after grouping.

Syntax

SELECT column_name(s)
FROM table_name
GROUP BY column_name(s)
HAVING condition;

Example: Countries with More Than 1 Customer

Find countries that have more than 1 customer.

SQL PLAYGROUND
⏳ Loading editor…

WHERE vs HAVING

  • WHERE: Filters individual records. Applied before grouping.
  • HAVING: Filters groups. Applied after grouping.

Example using both: Select customers from 'Mexico' or 'UK' only, group by country, and show only groups with at least 2 customers (although in our small data set this might be trivial).

SQL PLAYGROUND
⏳ Loading editor…