Answer the question
In order to leave comments, you need to log in
How to solve the sampling problem?
I use this query to select 14 random records:
"SELECT r1.name FROM `objects` AS r1 JOIN (SELECT CEIL(RAND() * (SELECT MAX(id) FROM `objects`)) AS id) AS r2 WHERE r1.id >= r2.id ORDER BY r1.id ASC LIMIT 14
RAND() * (SELECT MAX(id) FROM `objects`)
returns 98 , then naturally only 2 records will be selected, instead of the 14 required, but you always need 14. SELECT MAX(id)-14
does not apply. Answer the question
In order to leave comments, you need to log in
Isn't it better to use php to take 14 random numbers from the range in this case, and then just pull them out of the database?
I draw your attention to the fact that it is ORDER BY RAND()
unrealistically slow thing on a large number of records.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question