后来请教了google,得到如下代码
SELECT * FROM table_name AS r1 JOIN (SELECT ROUND(RAND() * (SELECT MAX(id) FROM table_name)) AS id) AS r2 WHERE r1.id = r2.id ORDER BY r1.id ASC LIMIT 5;
(本文来源于图老师网站,更多请访问http://m.tulaoshi.com/mysql/)执行效率需要0.02 sec.可惜的是,只有mysql 4.1.*以上才支持这样的子查询.