Difference between Where vs Having

Context:

  • WHERE is used to filter rows based on individual records before any grouping or aggregation.
  • HAVING is used to filter the results of a query based on aggregated values after grouping.

Usage:

  • Use WHERE for filtering individual records in a table.
  • Use HAVING for filtering grouped results based on aggregated values.

Aggregation:

  • WHERE typically involves conditions on individual columns.
  • HAVING involves conditions on aggregated values obtained through aggregate functions like COUNT, SUM, AVG, etc.