Quantcast
Viewing latest article 1
Browse Latest Browse All 20

Answer by Jack Briner for Select n random rows from SQL Server table

If you know you have approximately N rows and you want approximately K random rows, you just need to pull any given row with a chance K/N. Using the RAND() function which gives you a fair distribution between 0 and 1, you could just do the following where PROB = K/N. Worked very quickly for me.

SELECT * FROM some_table WHERE RAND() < PROB


Viewing latest article 1
Browse Latest Browse All 20

Trending Articles



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