Mysql 随机查询10条数据效率最快的查询方法
SELECT * FROM s_user WHERE id>= ((SELECT MAX(id) FROM s_user)-(SELECT MIN(id) FROM s_user)) * RAND() + (SELECT MIN(id) FROM s_user) LIMIT 10
select * from articles where id>=(select floor(rand() * (select max(id) from articles))) order by id limit 10
SELECT
*
FROM
`t_topic` AS t1
JOIN (
SELECT
ROUND(
RAND() * (
(SELECT MAX(id) FROM `t_topic`) - (SELECT MIN(id) FROM `t_topic`)
) + (SELECT MIN(id) FROM `t_topic`)
) AS id
) AS t2
WHERE
t1.id >= t2.id
ORDER BY
t1.id
LIMIT 10;
// ...............................................................
SELECT
*
FROM
`t_topic`
WHERE
id >= (
SELECT
floor(
RAND() * (SELECT MAX(id) FROM `t_topic`)
)
)
ORDER BY
id
LIMIT 10;
作者:百里求一
出处:http://www.cnblogs.com/bergus/
我的语雀: https://www.yuque.com/barry.bai
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。