Getting A Random Row From A MS SQL Table

To get a random row from a Microsoft SQL database you need to use the NEWID() function. This will generate a new random number for each row and order them by that new number. This is used in conjunction with the TOP clause to limit the amount of returned rows to one.

SELECT TOP 1 value FROM table ORDER BY NEWID()

 

Add new comment

The content of this field is kept private and will not be shown publicly.
CAPTCHA
7 + 8 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.