In case you do this because of an order or a random situation - I started using the following style:
SELECT id, value FROM list HAVING RAND() > 0.9
If you need this to be random, but manageable, you can use seed (PHP example):
SELECT id, value FROM list HAVING RAND($seed) > 0.9
Finally - if this is something like something you need to control completely, you can actually add a column that contains a random value whenever a row is inserted, and then query using this
SELECT id, value FROM list HAVING `rand_column` BETWEEN 0.8 AND 0.9
Since this does not require sorting, or ORDER BY
is O (n), not O (n lg n)
source share