I’ve a very big table (around 19.000.000 records), and I want to select 10 rows randomly.
I found this solution:
select *
from my_table as one
where one.id >=
(
select FLOOR(rand() * (select max(two.id) from my_table as one)) as currid
)
limit 10
That should work.
But, if I execute only the random part I get very often big ids (5, 6, 12, 15 milions, for example), but the complete query return always low ids (2k, 5k, 8k, …).
If I replace the where condition with a static value (e.g. 12 milion) i get the correct result.
Can’t understand how it is possible.
Regards