-- 删除多余的重复记录(多个字段),只保留最小id的记录 SELECT * FROM logistics_info_new WHERE id IN ( SELECT stu_repeat_copy.id FROM ( SELECT id FROM logistics_info_new WHERE (logistics_no) -- 注意:此处一定要加括号,当成联合字段来处理 IN ( -- 查找学号和姓名均重复的学生信息 SELECT logistics_no FROM logistics_info_new GROUP BY logistics_no HAVING COUNT(1) > 1 ) AND id NOT IN ( -- 查询最小id的记录 SELECT MIN(id) FROM logistics_info_new GROUP BY logistics_no HAVING COUNT(1) > 1 ) ) AS stu_repeat_copy );
原文:https://www.cnblogs.com/itworkers/p/15268484.html