关于数据库的去重

数据库中存在大量的重复内容,并且存在着外键关系

先删除外键的,以内容分组,查询条数大于一的,将该id在多对多的表中删除

delete from poem2cls where poem_id in(select id from (select id,count(*)as count from poem group by content having count>1)as a);

然后在删除拥有重复内容的表中的重复数据

 delete from poem where id in(select id from (select id,count(*)as count from poem group by content having count>1)as a);

然后循环,直至没有重复内容

猜你喜欢

转载自www.cnblogs.com/wwg945/p/9181248.html