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.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Union Ordering

Author  Topic 

tjforce
Starting Member

8 Posts

Posted - 2006-03-29 : 14:51:44
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 + field3
FROM table1
UNION
SELECT field1 + field 2 + field3
FROM table2

The 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
-PatP
Go to Top of Page
   

- Advertisement -