Quantcast
Viewing all articles
Browse latest Browse all 20

Answer by Sarsaparilla for Select n random rows from SQL Server table

It appears newid() can't be used in where clause, so this solution requires an inner query:

SELECT *FROM (    SELECT *, ABS(CHECKSUM(NEWID())) AS Rnd    FROM MyTable) vwWHERE Rnd % 100 < 10        --10%

Viewing all articles
Browse latest Browse all 20

Trending Articles



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