By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,377 Members | 3,052 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,377 IT Pros & Developers. It's quick & easy.

Random sample of rows

P: 1

I'd like to know if it is possible to make a random sample of a number/percentage of rows with the same value, i.e. to select randomly 6000 registers of field "x" where x=0

Thank you
Dec 5 '08 #1
Share this Question
Share on Google+
2 Replies

Expert 100+
P: 700
You can get a random sample, but I'm not sure if it is possible to set the size of a sample with one query.
Expand|Select|Wrap|Line Numbers
  1. select * from table where x=1 and random()<0.5;
Dec 7 '08 #2

Expert 5K+
P: 5,058

You can do this by using the random() function with the ORDER BY clause, and by adding a LIMIT clause.

For example:
Expand|Select|Wrap|Line Numbers
  1. SELECT * FROM testTable 
  2. WHERE value = 'SomeValue' 
  3. ORDER BY random() 
  4. LIMIT 10;
Dec 29 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.