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


This content was proof-read by Grammarly. You can Try Grammary for FREE

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
Newsletter Signup

Subscribe to our weekly newsletter below and never miss the latest product or an exclusive offer.

Newsletter Signup

Subscribe to our weekly newsletter below and never miss the latest product or an exclusive offer.

%d bloggers like this: