Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sort order (I think)

Status
Not open for further replies.

AndyApp

Programmer
Dec 20, 2001
259
GB
I'm pulling data back from SQL to ASP at the moment via two recordsets but I'm having trouble paging with two recordsets so am wondering if there's a way to combine the SQL as they look at the same things anyway.

It all pivots around a 'ListingType' column that is either 1 or 2. When the results are back the 2's MUST be BEFORE the 1's. Easy enough. However, all the 2's must be in a random order as must the 1's. I can do it just pulling one or the other back using NEWID() but don't know how to make 2's come before 1's and random?

I think that makes sense??
 
I was sure i'd tried that. anyhow it worked, didnt think it would be that easy. cheers clflava
 

From my understanding, the SQL should be:

select t3.f3
from
(
select 1 as f1, newid() as f2, col as f3 from T2
union
select 2, newid(), col from T1
) t3
order by t3.f1, t3.f2
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top