HAVING clause
Meaning in databases & SQL, with examples
In databases & SQL, HAVING clause means: The part of a SQL query that filters groups after GROUP BY has run, usually using the result of an aggregate function such as COUNT or SUM.
In Turkish: HAVING koşulu, grup filtresi
How it is used
The key rule: WHERE filters rows before grouping, HAVING filters groups after grouping. A typical example is HAVING COUNT(*) > 5. Putting a plain row filter in HAVING works but is slower, so it belongs in WHERE. 'WHERE vs HAVING' is a classic interview question.
Example sentences
Use a HAVING clause to list only the cities with more than 100 customers.
Move the date filter from the HAVING clause to WHERE so fewer rows get grouped.
Common collocations
- HAVING COUNT(*)
- GROUP BY ... HAVING
- filter groups
- WHERE vs HAVING
Related terms
This word in other fields
The same English word can have a different meaning in another field:
More terms: SQL Statements and Queries
Practise with graded reading
Reading at the right level is the fastest way to make new words stick. Pick free English books by level:
