A HAVING clause in SQL specifies that an SQL SELECT statement must only return rows where aggregate values meet the specified conditions.
WHERE is taken into account at an earlier stage of a query execution, filtering the rows read from the tables.
After the aggregating operation, HAVING is applied, filtering out the rows that don't match the specified conditions.
Therefore, WHERE applies to data read from tables, and HAVING should only apply to aggregated data, which isn't known in the initial stage of a query.
[clarification needed] To return a list of department IDs whose total sales exceeded $1000 on the date of January 1, 2000, along with the sum of their sales on that date: Referring to the sample tables in the Join example, the following query will return the list of departments which have more than 1 employee: HAVING is convenient, but not necessary.