3 ms·
I don't think HAVING is strictly needed, but you need to use a sub-query. SELECT x ... HAVING y => SELECT * FROM (x ...) t WHERE y
by tgv 5y ago
I don't think HAVING is strictly needed, but you need to use a sub-query.
SELECT x ... HAVING y => SELECT * FROM (x ...) t WHERE y
- throwawayffffas 5y agoYeah, you are correct it's really just syntactic sugar for that. As another comment points out, WHERE and HAVING are just σ in relational algebra.
- maweki 5y agoIn that sense, HAVING and WHERE being different is basically a "free" subquery without allowing subqueries. One inner σ (WHERE) and one outer σ (HAVING). If subqueries are allowed, then you don't need that.
- FedericoRazzoli 5y agoYou are correct, HAVING is essentially syntax sugar. But to be fair, I'm glad it exists.
- tgv 5y agoSure, and I remember the version of mySQL that didn't have sub-queries. Having HAVING has your back, then.