What is the difference between WHERE and HAVING clauses?


In fact, their functions complement each other.

  • A WHERE clause is used is filter records from a result. The filter occurs before any groupings are made.
  • A HAVING clause is used to filter values from a group.

That means the WHERE clause is first applied to the result and then, the remaining rows summarized according to the GROUP BY.