当前位置:   article > 正文

mysql使用limit进行分页查询 数据重复问题_limit有两个分数一样的怎么办

limit有两个分数一样的怎么办

问题描述:
SELECT t1.*, t2.dept_id AS sponsorId, t2.annual AS annual, t2.batch_name AS batchName, t3.real_name AS userName, t3.personnel_type AS personnelType, t3.post AS postName, t4.name AS deptName FROM tb_democratic_review t1 LEFT JOIN tb_review_batch t2 ON t1.batch_id = t2.id LEFT JOIN sys_user t3 ON t1.user_id = t3.id LEFT JOIN sys_dept t4 ON t1.dept_id = t4.id WHERE t1.del_flag = '0' AND t1.review_object = 2 AND t1.batch_id = "1475747396726120450" AND t2.annual = "2021年" AND t1.dept_id IN ( 1399979828270182402 ) ORDER BY create_date DESC LIMIT 0,10;
当使用limit进行分页查询时,出现数据重复的现象。
解决方法:
可以通过加上order by子句并保证排序字段的唯一性来解决。
由于上述sql中order by 后面的create_date 在数据库可能有重复的值,所以将排序字段换为主键或不重复的索引即可。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/IT小白/article/detail/139387
推荐阅读
相关标签
  

闽ICP备14008679号