PostgreSQL SyntaxLesson 38Free preview
PostgreSQL HAVING
This lesson is part of PostgreSQL · All levels
Summary
HAVING filters the results of groupings after GROUP BY is run, for example only displaying groups with numbers above a certain threshold. The key difference with WHERE is the time of application: WHERE filters the raw line, HAVING filters the aggregate result. Both can be used simultaneously in a query.
Key points
- Having filtered the aggregate results per group after GROUP BY.
- WHERE filters the line before grouping.
- The HAVING condition may contain aggregate functions such as COUNT and SUM.
- The HAVING clause is optional in the query.
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.