thinQmaster Virtual testing partner Adaptive practice exams that find your weak spots and drill them. Every answer explained. From $69
Enroll

thinQmaster

Find your exam

Five questions free, before you decide.

Step 1 · choose a vendor

In one of our camps? Your practice exams come with the tuition — they are on your study page already.

Data & Analytics · Foundational

HAVING Clause

The clause that filters groups after GROUP BY, typically using aggregate conditions.

Definition

HAVING is evaluated after grouping and aggregation, so it can reference aggregate functions. For performance, row-level conditions belong in WHERE so fewer rows are grouped.

Example

SELECT CustomerID, COUNT(*) FROM Orders GROUP BY CustomerID HAVING COUNT(*) > 5;

Exam tip

WHERE filters rows before aggregation; HAVING filters groups after aggregation. This is a very common exam item.

Don't confuse it with

Related terms