Like somuch.com on Facebook Share somuch.com on Facebook somuch.com on Twitter Reddit LinkedIn Pinterest
Newest Tips & Tricks...

Home :: Tips & Tricks :: Microsoft SQL Server

How to get a random row from a table

select top 1 columns....
from table
order by newid()

-- choosing between first 20 rows
set ROWCOUNT 20
select top 1 *
from (Select * from table)
order by newid()
set ROWCOUNT 0

Source: http://weblogs.sqlteam.com/mladenp/archive/2005/08/01/7421.aspx

Recommended Links...