The lexical ordering is:
SELECT FROM WHERE GROUP BY HAVING UNION ORDER BY
FROM WHERE GROUP BY HAVING SELECT UNION ORDER BY
But you need first to order by column to get the rows in the desired order, while SELECT just indicates which column from the rows to return.
source table -> filtered rowset -> grouped rowset -> filtered grouped rowset -> ordered rows -> ordered rows with selected columns only
Source: I was working several years as a Human Query Planner for the columnar DB ;)
The lexical ordering is:
while the logical order is: [1] https://blog.jooq.org/10-easy-steps-to-a-complete-understand...