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();
The absence of evidence is not evidence of absence
- Martin Rees
The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
- Phil Parkin
October 8, 2019 at 9:27 pm
thanks, Phil. Can I use random () to rewrite the same query?
Thanks.
October 8, 2019 at 9:59 pm
thanks, Phil. Can I use random () to rewrite the same query?
Please post the link to the T-SQL random() function that you intend to use.
The absence of evidence is not evidence of absence
- Martin Rees
The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
- Phil Parkin
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 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply