MYSQL 随机选取几条数据

 

SELECT * FROM tablename AS r1 JOIN (SELECT ROUND(RAND() *(SELECT MAX(id)FROM tablename)) AS id) AS r2 WHERE r1.id >= r2.id ORDER BY r1.id ASC LIMIT 10000;

 

SELECT * FROM tablename ORDER BY rand() LIMIT 5

 

第一种速度比第二种快的多

posted @ 2013-12-02 15:12  杨桃  阅读(441)  评论(0编辑  收藏  举报