The HAVING clause was added to SQL because the WHERE keyword could not be used with aggregate functions.
In this tutorial we will use the well-known Northwind sample database.
Below is a selection from the "Orders" table:
And a selection from the "Employees" table:
|1||Davolio||Nancy||1968-12-08||EmpID1.pic||Education includes a BA....|
|2||Fuller||Andrew||1952-02-19||EmpID2.pic||Andrew received his BTS....|
|3||Leverling||Janet||1963-08-30||EmpID3.pic||Janet has a BS degree....|
Now we want to find if any of the employees has registered more than 10 orders.
We use the following SQL statement:
Now we want to find if the employees "Davolio" or "Fuller" have registered more than 25 orders.
We add an ordinary WHERE clause to the SQL statement: