Xah Lee wrote:
>
> Suppose I want 10 rows randomly selected from a table. How do I do that?
>
> Thanks.
>
> Xah
Hi Xah
1) Add a FLOAT column to the table:
ALTER TABLE random_selectable ADD random FLOAT;
2) Fill this column with random numbers:
UPDATE random_selectable SET random = RAND();
3) Get 10 values:
SELECT * FROM random_selectable ORDER BY random LIMIT 10;
If you don't want to UPDATE the random column for each SELECT, then you can add a random
criteria in the WHERE clause e.g.:
SELECT * FROM random_selectable WHERE random > RAND()/2 ORDER BY random LIMIT 10
Tschau
Christian