Wimdows.NET

Wim's .NET blog

Random records from table

Hi all,

Great to be part of this blogging community. I will try to submit several posts each week and will make sure they contain snippets of code here and there.

Now, what would you do to select a random set of several records from a SQL Server database table?

A couple of months ago I came across the following simple, but yet very effective solution to do just that. For instance to get 10 random quotes from a Quotes table:

SELECT TOP 10 * FROM Quotes ORDER BY NEWID()

Personally I think it's pure gold.

Posted: Apr 01 2004, 10:21 PM by Wim | with 2 comment(s)
Filed under:

Comments

rajbk said:


Thanks for the tip!
# April 1, 2004 8:21 PM

J. H. Rasmussen said:

Works great, thanks!

# August 2, 2008 4:51 PM
Leave a Comment

(required) 

(required) 

(optional)

(required)