Logical Processing Order of the
SELECT statement:
The main statement used to retrieve data in T-SQL is the SELECT statement. Following are the main query clauses specified in the order that you are supposed to type them
(known as “keyed-in order”):
- SELECT
- TOP
- DISTINCT
- FROM
- JOIN
- ON
- WHERE
- GROUP BY
- WITH CUBE or WITH ROLLUP
- HAVING
- ORDER BY
But as mentioned, the logical query processing order, which is the conceptual interpretation order, is different. It starts with the FROM clause.
The following steps shows the logical processing order, or binding order, for a SELECT statement.
Here is the logical query processing order
of the main query clauses:
Note that the actual physical execution of the statement is determined by the query processor and the order may vary from this list.
- FROM
- ON
- JOIN
- WHERE
- GROUP BY
- WITH CUBE or WITH ROLLUP
- HAVING
- SELECT
- DISTINCT
- ORDER BY
- TOP