Quantcast
Channel: Select n random rows from SQL Server table - Stack Overflow
Viewing all articles
Browse latest Browse all 20

Answer by Daniel Brückner for Select n random rows from SQL Server table

$
0
0

Just order the table by a random number and obtain the first 5,000 rows using TOP.

SELECT TOP 5000 * FROM [Table] ORDER BY newid();

UPDATE

Just tried it and a newid() call is sufficent - no need for all the casts and all the math.


Viewing all articles
Browse latest Browse all 20

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>