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 query with different ORDER BY's

Author  Topic 

AjarnMark
SQL Slashing Gunting Master

3246 Posts

Posted - 2001-07-11 : 18:23:48
I want to do a Union of two different queries with each of the two queries sorted differently (using SQL Server 7.0). For example:


SELECT StartDate, Duration, Title
FROM Events
WHERE Duration <= 7
ORDER BY StartDate

UNION

SELECT StartDate, Duration, Title
FROM Events
WHERE Duration > 7
ORDER BY Title


My test results seem to indicate that you can only have one ORDER BY for the entire Union'ed resultset. I know I can fall back to using a Temporary Table and insert the subsets separately, but I'd rather not.

Thanks in Advance...

Mark

   

- Advertisement -