MySQL HAVING Clause (original) (raw)

Last Updated : 26 Mar, 2026

MySQL provides the HAVING clause to filter grouped data based on aggregate conditions. It is useful for applying conditions on results obtained after using the GROUP BY clause.

Syntax:

SELECT column1, column2, AGGREGATE_FUNCTION(column_name) FROM table_name GROUP BY column1, column2 HAVING AGGREGATE_FUNCTION(column_name) condition;

Where:

Demo MySQL Database

To understand the HAVING clause, we will create a sample table and use it to demonstrate how grouping and filtering work together.

Screenshot-2026-03-26-143820

Examples of MySQL HAVING Clause

Example 1: Filtering Groups by Count

In this example we will the find products that have been sold more than once.

**Query:

SELECT product, COUNT() FROM sales GROUP BY product HAVING COUNT() > 1;

**Output:

Screenshot-2026-03-26-151221

Example 2: Filtering Groups by Sum

Here we will find products with a total quantity sold greater than 10

**Query:

SELECT product, SUM(quantity) FROM sales GROUP BY product HAVING SUM(quantity) > 10;

**Output:

Screenshot-2026-03-26-151339