Wednesday 12 December 2012

How to get random record from table in SQL


To get random record from table we use NEWID()function. Example

USE AdventureWorks

SELECT TOP 1 * FROM Production.Document
ORDER BY NEWID()

NEWID() is used to generate UNIQUEIDENTIFIER
SELECT  NEWID()

No comments:

Post a Comment