How to select N random rows using a T-SQL Query ?

You can use the TOP keyword and specify the number to retreive the TOP N records that the query returns. Additionally , order the records by newid() function using the ORDER BY clause to make the records random.

How to select N random rows using a T-SQL Query ?

use AdventureWorks2014 
GO 
SELECT top 10  percent * 
FROM HumanResources.Employee order by newid()
image

Leave Your Comment

Liked this content?. Please spread the word :)