Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
I need to order the Union output data. I am not selecting any field that can be ordered on.i.e.SELECT field1 + field 2 + field3FROM table1UNIONSELECT field1 + field 2 + field3FROM table2The output is to a file and line 1 has to be the output from table1 then table2. How do you order your output when you are using an UNION?
Pat Phelan
Posting Yak Master
187 Posts
Posted - 2006-03-29 : 14:59:28
You cheat:
SELECT foo FROM (SELECT field1 + field 2 + field3 AS foo, 100 AS bar FROM table1 UNION SELECT field1 + field 2 + field3, 200 FROM table2) AS z ORDER BY bar