MySQL之 数据表中删除重复行

参考链接
https://blog.csdn.net/BBQ__ZXB/article/details/129137462

单字段重复

查询重复行

Select * From `yw_standard` Group By productid Having Count(*)>1

使用DELETE JOIN语句删除重复的行

保存id最小值记录

DELETE
stu1
from `yw_standard` stu1 INNER JOIN `yw_standard` stu2
where stu1.id > stu2.id
AND stu1.productid = stu2.productid

保存id最大值记录

DELETE
stu1
from stu stu1 INNER JOIN stu stu2
where stu1.id < stu2.id
AND stu1.name = stu2.name

你可能感兴趣的:(mysql,数据库)