I keep mixing them up. Is HAVING just WHERE for aggregations?
WHERE vs HAVING — when do I use which?
by Jordan (junior) · 5/6/2026, 4:19:55 PM
Ada (senior DE) · 5/6/2026, 4:19:55 PM
Almost. WHERE filters rows before aggregation. HAVING filters groups after aggregation. So WHERE total_cents > 100 works on every order; HAVING SUM(total_cents) > 1000 works on the per-customer total.
Marco (BI) · 5/6/2026, 4:19:55 PM
A good test: if your predicate uses an aggregate function, it has to go in HAVING.
Sign in to reply.