赞
踩
问题描述:
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 在数据库可能有重复的值,所以将排序字段换为主键或不重复的索引即可。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。