How to select N random records from a SQL Server table

If you want to select N random records from a SQL Server table, you need to change the clause as follows:

select top N * from tableName order by newid()

For example, to select 5 random customers in the customers table, you use the following query:

select top 5 * from customers order by newid()

Some SQL Server tools you can try: https://www.withdata.com/sql-server/

Convert your data online, free

Free in-browser converters for CSV, Excel, JSON, XML and SQL: Withdata Online Data Conversion. Large files, batch conversion or scheduling? See the offline desktop apps, or browse all data conversion tools.


Posted

in

by