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.
Ready to master this question?
Generate a complete walkthrough — background, the full answer in plain language, a working code example explained line by line, a real-world scenario, common mistakes, and how this same question gets asked in different ways.
Sign in to generate a response