This question already has an answer here:
I have one question that confusing me.
By logical query processing, the
SELECT clause comes before the
ORDER BY clause, and in theory, every step in a query creates a virtual table. So, how is it even possible to order result by a column that is not listed in the
SELECT clause, when the
SELECT clause generates a virtual table with the selected columns?
In case your query has a
GROUP BY clause, then the behavior become normal, but in the absence of a
GROUP BY clause, it seems a little tricky. Does anybody have an explanation?