查找、删除表中多余的重复数据

假设有一张tabA的表,以其中的name字段判断是否重复

一. 查找表中多余的重复记录,重复记录根据表中的单个字段来判断

      select * from tabA  where  name  in (select  name from   tabA  group by   name  having count (name) > 1)

二. 删除表中多余重复的记录,只保留其中一条

delete from tabA   where

name  in (select   name  from tabA  group by   name having count (name) > 1)

and rowid not in (select min(rowid) from   tabA group by name having count(name)>1)

猜你喜欢

转载自blog.csdn.net/guocunlei25/article/details/92803019