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
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy