What is the difference between a HAVING clause with an aggregate and a WHERE clause for the same logical filter?

SQL Fundamentals Hard

SQL Fundamentals — Hard

What is the difference between a HAVING clause with an aggregate and a WHERE clause for the same logical filter?

Key points

  • WHERE filters individual rows before grouping
  • HAVING filters groups after aggregation
  • HAVING can reference aggregates, WHERE cannot
  • HAVING is used for filtering grouped data

Ready to go further?

Related questions