Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 Site Related Forums
 Article Discussion
 Article: Returning a Single Random Row
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Ask SQLTeam Question

0 Posts

Posted - 09/23/2000 :  12:11:01  Show Profile  Visit AskSQLTeam's Homepage  Reply with Quote
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.

Starting Member

United Kingdom
3 Posts

Posted - 08/22/2001 :  06:25:19  Show Profile  Send SteveMc an ICQ Message  Reply with Quote
That is an ingenius bit of trickery!

With a bit of tweaking I managed to use this method to set up a random data generator for a temperature sensor, based on a table containing outline values, your article has probably saved me a days work there 8)...

Go to Top of Page

Starting Member

36 Posts

Posted - 03/28/2002 :  14:50:14  Show Profile  Reply with Quote

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

Jedi Yak

2489 Posts

Posted - 03/28/2002 :  15:57:47  Show Profile  Visit MichaelP's Homepage  Reply with Quote
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.


Go to Top of Page

Constraint Violating Yak Guru

468 Posts

Posted - 03/28/2002 :  16:00:27  Show Profile  Reply with Quote
My mind is blown . . .

Go to Top of Page

SQL Gigolo

1157 Posts

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


Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.02 seconds. Powered By: Snitz Forums 2000