all groups > sql server mseq > october 2003 >
You're in the

sql server mseq

group:

randomize the order of rows returned


randomize the order of rows returned Calvin Steele
10/6/2003 1:27:39 PM
sql server mseq:
Is there a way ORDER BY clause can randomize the order of rows returned?

eg:
SELECT column1
FROM table1
ORDER BY column1 ASC

Here instead of ASC or DESC, I want the order to be random.

Is there is anyother way to do this if not possible by ORDER BY?

Thanks.

Re: randomize the order of rows returned Anith Sen
10/6/2003 3:56:00 PM
In t-SQL, though not recommended & undocumented, you can do:

ORDER BY New_Id()

If you have a unique key column, you can also do:

ORDER BY RAND((@@IDLE % keycol) +
DATEPART(ms, CURRENT_TIMESTAMP) + keycol)

--
- Anith
( Please reply to newsgroups only )

Re: randomize the order of rows returned Anith Sen
10/6/2003 3:59:58 PM
A typo: it should be NEWID() --- no underscore.

--
- Anith
( Please reply to newsgroups only )

Re: randomize the order of rows returned Calvin Steele
10/6/2003 4:50:34 PM
Thanks Anith, that worked.


[quoted text, click to view]

AddThis Social Bookmark Button