In theory, every statement in SQL Server create virtual table passed to next statement. In other words, when FROM and Where clause are finished, next step is SELECt columns from virtual group created step before.
But, it is possible to order result set by column that is not listed in select list.
How is it possible, when SELECT clause are executed before ORDER BY and which primary task is to select columns for rendering?
It is a little confusing or I don't get something.
Best Answer
It's not always possible:
(VT5 is virtual table returned generated by
SELECT
)Explanation is taken from "Inside SQLServer 2008 T-SQL Querying" - I'm not sure if this particular chapter is available online (Step 6: The Presentation
ORDER BY
Phase, p.16.)Thus,
gives an error: