删除重复数据Mysql

 

-- 删除多余的重复记录(多个字段),只保留最小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

);

  

删除重复数据Mysql

上一篇:3ds Max实例-3ds Max制作客厅场景实例教程


下一篇:记mysql存储过程给变量赋值的坑