Tech
SQL Execution Order Internals: Why WHERE Fails on Aliases but ORDER BY Succeeds
Ever wondered why this query fails in SQL?
SELECT department_id , COUNT ( * ) AS emp_count
FROM employees
WHERE emp_count > 5 -- ❌ Error: Invalid column name 'emp_count'
GROUP BY department_id ;
The 6-Stage Execution Engine:
FROM & JOIN — Load source tables & evaluate join conditions
WHERE — Filter raw rows before grouping
GROUP BY — Aggregate rows into buckets
HAVING — Filter aggregated buckets
...
Read the full discussion on Dev.to
This article was aggregated from Dev.to. Click to join the conversation.
View on Dev.to