What is the exact logical order of execution for a SQL SELECT query?
The logical processing order is: 1. FROM (including JOINs), 2. ON (join conditions), 3. WHERE (row-level filtering), 4. GROUP BY (row aggregation), 5. HAVING (aggregate filtering), 6. SELECT (projections & window functions), 7. DISTINCT (deduplication), 8. ORDER BY (sorting), 9. LIMIT / OFFSET (pagination). Understanding this explains why column aliases defined in SELECT cannot be referenced in WHERE, but can be used in ORDER BY.