在MYSQL数据库中如何通过多字段的查询并且删除多余的重复数据,最后保留某一字段的最小值,之前文章有提到如何删除表中多余的重复记录通过单字段并且保留最小记录的方法,此次的条件和上次差不多,增加了多字段的查询,结合一点博主之前发布的几篇sql文章,很容易推理出这条sql的写法。如下:
delete from user a where (a.cid,a.seq) in (select cid ,seq from user group by cid,seq having count(*) > 1) and rowid not in (select min(rowid) from user group by cid ,seq having count(*)>1)
原理和之前的一样,只是增加了多字段的查询。