SQL Logical Processing Order Deep Dive
If you're new to SQL, understanding the SQL logical processing order is the most important skill for writing efficient and bug-free code. Unlike other programming languages, SQL logically doesn't process the code top to bottom or left to right. In the video below, I provided examples of typical pitfalls/gotchas when creating SQL queries. We'll look into: Overview of SQL Logical Processing Order. Why query execution plan can be different from logical order. Why we can't use aliases defined in SELECT list in WHERE clause. Different between WHERE filters versus HAVING filters. Using subquery to work around error when adding aggregate functions in WHERE clause. Using subquery and CTE to work around error when adding window functions in WHERE clause. Examine how expressions, aliases, and window functions are processed. Use window functions in ORDER BY clause. Tips on how to read SQL queries.