SQL Practice Logo

SQLPractice Online

HAVING Clause: Performance

Module: Aggregate Functions & Grouping

**Performance Tips:**

- Always put row filters in WHERE (faster)

- HAVING cannot use indexes on aggregates

- Filter with WHERE before GROUP BY reduces data

- Use HAVING only for aggregate conditions

WHERE reduces data before grouping

Put row filters in WHERE, not HAVING

Index columns in WHERE clauses

HAVING evaluated after aggregation

Avoid complex expressions in HAVING

Using HAVING for row filters

Forgetting GROUP BY with HAVING

Using aggregates in WHERE

Inefficient filter placement

Confusing WHERE and HAVING order