随机取数据

SELECT * FROM tablename ORDER BY RAND() LIMIT 1

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;

 

select *, rand() as random from 'table' order by random limit 1

posted @ 2014-03-15 18:25  忘忧般若汤  阅读(165)  评论(0编辑  收藏  举报