Facebook Twitter Reddit LinkedIn

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
© 2007-2019 All rights reserved.   Part of the somuch.com group of trusted web sites.   PO Box 351031, Palm Coast FL 32135-1031