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
 Site Related Forums
 Article Discussion
 Article: Returning a Single Random Row

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2000-09-23 : 12:11:01
Earlier we published an article on quickly creating a sequential number. In this article we'll use that technique to quickly select one random record from a table. We'll even cover assigning a weight to each record. Can someone say banner ads?

Article Link.

motokevin
Starting Member

36 Posts

Posted - 2002-03-28 : 14:50:14
Dudes,

I found a method to pull a single random row that is soooooo easy (I wish I'd thought of it.) No min/max or Ubound/lbound or averaging.

Select top 1 [data you want from row]
from [table or whatever]
Order By NEWID()



Go to Top of Page

MichaelP
Jedi Yak

2489 Posts

Posted - 2002-03-28 : 15:57:47
OMG, that works!! Now that is an elegant solution!
Now, I'm not sure on how random it really is, but it seems pretty random in my testing.

Michael


Go to Top of Page

Jay99

468 Posts

Posted - 2002-03-28 : 16:00:27
My mind is blown . . .

http://www.microsoft.com/sql/using/tips/development/queryresults.asp

Jay
<O>
Go to Top of Page

JustinBigelow
SQL Gigolo

1157 Posts

Posted - 2002-03-28 : 17:12:01
Jay, thanks for the link I read thru all those tips and found some cool info.

Justin

Go to Top of Page
   

- Advertisement -