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)
 What's the best way to randomize rows

Author  Topic 

technicalsachin
Starting Member

1 Post

Posted - 2005-07-04 : 00:31:38
will u plz suggest me the way to randomize rows in a table.
i just want random images to display on a web page.

derrickleggett
Pointy Haired Yak DBA

4184 Posts

Posted - 2005-07-04 : 00:42:03
ORDER BY NEWID()

MeanOldDBA
derrickleggett@hotmail.com

When life gives you a lemon, fire the DBA.
Go to Top of Page

Bustaz Kool
Master Smack Fu Yak Hacker

1834 Posts

Posted - 2005-07-04 : 00:42:25
Have you looked at the RAND function?

select MyImage
from MyTable
where ImageID = cast((Rand() * <Number of Images> as Int) + 1


Assumes that the images arenumbered 1 through <Number of Images>

HTH

=================================================================
'Tis with our judgements as our watches: none Go just alike, yet each believes his own. -Alexander Pope, poet (1688-1744)
Go to Top of Page

AndrewMurphy
Master Smack Fu Yak Hacker

2916 Posts

Posted - 2005-07-04 : 06:55:01
Rand() is not unique for every record, in a resultset....newid() is.

Try

Select *, rand() from yourtable....and inspect the rand values...
and then compare to
select *, newid() from yourtable
Go to Top of Page
   

- Advertisement -