October 8, 2019 at 9:16 pm
I need to extract randomly to select 10% of the rows from a table. Kindly advise how to write the t-SQL.
Thanks.
October 8, 2019 at 9:24 pm
Use NEWID() to force randomness.
SELECT TOP (10) PERCENT
*
FROM sys.columns
ORDER BY NEWID();
October 8, 2019 at 9:27 pm
thanks, Phil. Can I use random () to rewrite the same query?
Thanks.
October 9, 2019 at 8:01 am
Phil's solution is definitely the more elegant but (for completeness) there is also a TABLESAMPLE clause.
Viewing 5 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply