SQLTeam.com | Weblogs | Forums

Union with Sort by


#1

Select PersonName as Name from person
union
Select CandidateName as Name from candidates

How can I sort the full list?
Thanks.


#2

One way:

SELECT [Name]
FROM
(
Select   PersonName as Name from person
union
Select CandidateName as Name from candidates
) AS X
ORDER BY [Name]

#3

That worked for me. Thank you.


#4

Select PersonName as Name from person
union
Select CandidateName as Name from candidates
Order by Name


#5

I've had trouble with that approach ... can't now remember why, and maybe it was "something slightly different". Wish I could remember now ...

... perhaps using TOP on one/some/all the UNIONs (and thus needing an ORDER BY on just that SELECT), which obviously is NOT this situation.