Press "Enter" to skip to content

Order Of Execution With SQL Server

Andrew Tobin explains the order of how a SQL statement gets processed:

For a particular query you may have the following components and they act in this order:

1 FROM / JOIN
2 WHERE 
3 GROUP BY 
4 HAVING 
5 SELECT
6 ORDER BY 
7 TOP / OFFSET-FETCH

Read on for more details.  This is why, for example, you can use an aliased column or calculation in the ORDER BY clause but not in the WHERE clause.