Retrieving Random Rows

Posted by on Dec 31, 2012 in SQL | 0 comments


You can run script below and it will give random rows every single time you run it:

 

USE AdventureWorks2012
GO

-- Method 1
SELECT TOP 100*
FROM SalesOrderDetail
ORDER BY NEWID()
GO


-- Method 2
SELECT TOP 100 *
FROM SalesOrderDetail
ORDER BY CHECKSUM(NEWID())
GO


Leave a Reply