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)
 Quick SQL sorting question

Author  Topic 

Sanatan
Starting Member

19 Posts

Posted - 2009-04-01 : 14:22:48
Hi, I need some quick help with a sorting issue.

I have two sets of data retrieved from a table and joined via a UNION.

I need to display the first set of data always above the second set. Is there any quick way to do this?

Data example:

SELECT Col1, Col2 from TblA Where (Col1 matching subquery1) <- Set1
union
SELECT Col1, Col2 from TblA Where (Col1 matching subquery2) <- Set2

I want the final result set to be shown in the same order as the above query.

Please let me know if you need additional details. Thanks,

sakets_2000
Master Smack Fu Yak Hacker

1472 Posts

Posted - 2009-04-01 : 14:38:21
[code]Select Col1, Col2
from
(
SELECT Col1, Col2,1 id from TblA Where (Col1 matching subquery1) <- Set1
union
SELECT Col1, Col2,2 from TblA Where (Col1 matching subquery2) <- Set2
)s
order by id[/code]
Go to Top of Page

Sanatan
Starting Member

19 Posts

Posted - 2009-04-01 : 14:42:28
Thanks Sakets... I just got it to work! Anyway, appreciate your quick help.
Go to Top of Page

sakets_2000
Master Smack Fu Yak Hacker

1472 Posts

Posted - 2009-04-01 : 14:43:42
np
Go to Top of Page
   

- Advertisement -