intermediateSQL Fundamentals Deep Dive — Data Types, NULL Handling & Query Execution Order
What is SQL's logical clause execution order, and why can't a SELECT-defined alias be used in that same query's WHERE clause?
The logical order is FROM, then WHERE, then GROUP BY, then HAVING, then SELECT, then ORDER BY, then LIMIT. Since WHERE is evaluated before SELECT has produced any aliases, a SELECT alias doesn't exist yet at the point WHERE runs — it's why the same alias works fine in ORDER BY, which runs after SELECT.
This is a Pro chapter
Sign in, then upgrade to Pro or Power to unlock this and the full Databases Mastery library.
What is SQL's logical clause execution order, and why can't a SELECT-defined alias be used in that same query's WHERE clause?