SQL Tips by Namwar Rizvi

May 9, 2007

More simpler way to return a random row from table

Filed under: Random row, tips — namwar @ 11:21 pm

Few days back, I posted a query to return a random row by using RowNum function. A reader has pointed out a more simpler way to achieve the same result. Following is the new and quicker way to return the random row:

select top 1 ColumnList
from TableName
order by newid()

Just replace “ColumnList” and “TableName” with list of columns and name of table respectively.

I will really appreciate, if someone can give comments about the performance of both approaches.


Blog at WordPress.com.