Reprence Html CSS javascript PHP MySQL Bootsrap

The MySQL HAVING Clause

The HAVING clause was added to SQL because the WHERE keyword cannot be used with aggregate functions.

HAVING Syntax

113

Demo Database

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

114

MySQL HAVING Examples

The following SQL statement lists the number of customers in each country. Only include countries with more than 5 customers:


The following SQL statement lists the number of customers in each country, sorted high to low (Only include countries with more than 5 customers):



Demo Database

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

115

And a selection from the "Employees" table:

116

More HAVING Examples

The following SQL statement lists the employees that have registered more than 10 orders:


The following SQL statement lists if the employees "Davolio" or "Fuller" have registered more than 25 orders: