Search⌘ K

HAVING

Explore how to use the HAVING clause in SQL to filter groups of rows after aggregation. This lesson clarifies the difference between HAVING and WHERE clauses, demonstrates queries with aggregate functions, and guides you on appropriate use cases to improve query efficiency and correctness.

We'll cover the following...

Having Clause

We are familiar with the WHERE clause that can be used to filter rows. In the same way, the HAVING clause allows us to filter groups. At times, the HAVING clause can be used to filter rows to display but that is not the intended use and can make the query slower. The HAVING clause should be used to decide what rows form each group. Remember the HAVING clause works on groups of rows whereas the WHERE clause works on individual rows. We’ll work with ...