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
 Transact-SQL (2000)
 Randomly Sort Records

Author  Topic 

csphard
Posting Yak Master

113 Posts

Posted - 2005-11-18 : 13:44:26
I used order by newid() with top 200 to get 200 records in random order and it works. Now they are asking well you got the information but Its not in order.

newid allows me to select my information which results 10000 - 15000
records

order by newid randomly sorts it and then I get the top 200.

Is there a way to get that top 200 and then sort it by something?

thanks

SELECT top 5
FROM Northwind..Orders
ORDER BY NEWID()

ehorn
Master Smack Fu Yak Hacker

1632 Posts

Posted - 2005-11-18 : 13:53:49
Sure, you can make the initial query a derived table and then sort the results. Something like:


select d.<column1>, d.<column2>
from
(
SELECT top 5 <column1>, <column2>
FROM <table>
ORDER BY NEWID()
) d
order by d.<column1>
Go to Top of Page
   

- Advertisement -