bugl
bugl
HomeLearnPatternsSearch
HomeLearnPatternsSearch

Loading lesson path

Learn/SQL/SQL Tutorial
SQL•SQL Tutorial

SQL HAVING Clause

Concept visual

SQL HAVING Clause

Pointer walk
two pointers
leftright102132436485116
left=0
right=6
1
3

Start at both ends

The SQL HAVING Clause

The HAVING

clause is used to filter the results of a GROUP BY query based on aggregate functions.

Unlike the WHERE

clause, which filters individual rows before grouping,

Having

filters groups after the aggregation has been performed.

HAVING Syntax

Select

column1, aggregate_function(column2), column3, ...

From

table_name

Where

condition

Group By

column1, column3

Having

condition -- The condition on grouped data

Order By

column_name

;

Demo Database

Below is a selection from the "Customers" table in the Northwind sample database:

CustomerID

CustomerName

ContactName

Address

City

PostalCode

Country

Alfreds Futterkiste

Maria Anders

Obere Str. 57

Berlin

12209

Germany

Ana Trujillo Emparedados y helados

Previous

SQL GROUP BY Statement

Next

SQL EXISTS Operator