Though the HAVING
clause specifies a condition that is similar to the purpose of a WHERE
clause, the two clauses are not interchangeable. Listed below are some differences to help distinguish between the two:
- The WHERE clause specifies the criteria which individual records must meet to be selcted by a query. It can be used without the GROUP BY clause. The HAVING clause cannot be used without the GROUP BY clause.
- The WHERE clause selects rows before grouping. The HAVING clause selects rows after grouping.
- The WHERE clause cannot contain aggregate functions. The HAVING clause can contain aggregate functions.