除非必须保证每次查询都得到5条数据,否则就不需要担心咯。。
如果必须的话建议用程序计算RAND的值~   RAND { 0 ~ COUNT(*)-5 }

解决方案 »

  1.   

    用两句select + 程序随机试试看,应该会比第一句快很多
      

  2.   

    绝对不要用ORDER BY rand()你可以考虑select min(id) as `min`,max(id) as `max`
    然后在PHP中rand($min,$max)出几个id,再select ... where id in ($ids)
      

  3.   


    要是我是两个表联合查询呢?应该如何优化我的这个sql呢?比如说:select * FROM act_photo,act_user where act_photo.userId = act_user.userId and type = 1 order by rand() limit 2