Skip to content
Advertisement

Order By in Union Nested selects

I have two really long selects that are both nested

How can I order these (both queries combined into one table results) by NewestMessage which is a type of datetime?

Advertisement

Answer

I would slightly alter your query to:

I am basically replacing your union of tuples to a subquery on a union query, using an ORDER BY with the column you want. Note that aliases in the second half of the union query are not necessary, and in fact will be ignored by SQL Server.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement