Freek's Blog

SQL en .NET vraagstukken en oplossingen die ik zoal tegenkom
posts - 199, comments - 123, trackbacks - 2, articles - 7

My Links

News

Google analytics script: Locations of visitors to this page

Article Categories

Archives

Post Categories

Image Galleries

Algemene links

MSDN

vb links

T-SQL: select random records from table

Posted on Thursday, June 03, 2010 9:20 AM

A nice way to select random records from a table is the use of NEWID().


Example:

Select TOP 5 * from [tablename] ORDER BY NEWID()

When run the above command twice, you will see that the output differs when you have more than 5 records, of course.

see also: http://msdn.microsoft.com/en-us/library/ms190348.aspx

 

 

 

Post Comment

Title  
Name  
Url
Comment   

ATTENTION: the code you need to copy is CaSe SeNsItIvE and is required to prevent spam.
Enter the code you see: