[英]MySQL - Select specific rows and only then randomize them
When I write 'SELECT * FROM table ORDER BY RAND() LIMIT 50'
mysql has to randomize the entire table then only fetch 50. What I want to do (in mysql, preferably not in php) is to fetch 50 rows THEN randomize them. 当我写
'SELECT * FROM table ORDER BY RAND() LIMIT 50'
mysql必须将整个表随机化,然后才取50。我想做的(在mysql中最好不在php中)是取50行然后将它们随机化。
Is there a way to do this in Mysql? 有没有办法在Mysql中做到这一点?
Have you tried something like this 你有没有尝试过这样的事情
SELECT *
FROM (
SELECT *
FROM table
LIMIT 50
) sub
ORDER BY RAND()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.