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.

1 Comment

Comments have been disabled for this content.