How to Select a random row with Microsoft SQL Server

September 12th, 2012 | Posted by Nitesh Luharuka in General | SQL Server | Utility

A quick post for all -

We often find situations where we need to retrieve random records from a MS SQL table. The below query does the same for you.

To generate a random record from a table in Microsoft SQL Server, we need to execute the following query:

SELECT TOP 1 * FROM tbl_name ORDER BY NEWID()

You can follow any responses to this entry through the RSS 2.0 You can leave a response, or trackback.

3 Responses



Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Support us!

If you like this site please help and make click on any of these buttons!

×