1 of 10 · Basics
In what order does SQL actually run a query?
Say this first
Not the order you write it. The database filters first, groups next, and only then picks columns.
Picture it
- 1FROM / JOIN Pick the tables and combine them.
Some databases let GROUP BY or HAVING use aliases, but WHERE never can.
Try it
Why does WHERE total > 100 fail when total is an alias defined in SELECT?
Common trap
Assuming SQL runs in the order you type it. That is why aliases fail in WHERE and aggregates fail in WHERE.
Say it like this
SQL runs FROM, WHERE, GROUP BY, HAVING, SELECT, ORDER BY, LIMIT, so WHERE can't see aliases or aggregates.
