duanqiao1961
2012-05-11 21:34
浏览 303
已采纳

ORDER BY RAND()返回重复项

I tried using distinct as well and it returns duplicates.

$cubes = mysql_query("SELECT distinct * FROM posts ORDER BY RAND() $limit ") or die(mysql_error());

I just want to take my posts table... and return it in a random order without duplicates.

图片转代码服务由CSDN问答提供 功能建议

我尝试使用distinct也返回重复项。

  $ cubes = mysql_query(“SELECT distinct * FROM posts ORDER BY RAND()$ limit”)或die(mysql_error()); 
   
 
 

我只是想 拿我的帖子表...并以随机顺序返回它,没有重复。

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • duanbing2963 2012-05-11 21:36
    已采纳

    Select only the distinct id's you need, e.g.

    SELECT distinct id FROM posts ORDER BY RAND() $limit
    

    Distinct works over 'all' rows you select, so if you (for example) have a unique timestamp field, chances are you'll return every single row.

    点赞 评论
  • dongxunhua2054 2012-05-11 21:37

    Are you sure that you want to execute a SELECT DISTINCT * FROM ... and not just a SELECT DISTINCT column_name FROM ... ?

    See the SQL DISTINCT STATEMENT doc for more infos.

    点赞 评论

相关推荐 更多相似问题