person表中有id和name两个字段,id是唯一值,若id相同,则认为记录重复。

  1. 查找重复id
select id from person group by id having count(*)>1复制代码
  1. 查找重复数据
select * from person where id in (select id from person group by id having count(*)>1)复制代码
  1. 删除重复记录,保留rowid最小的记录
delete from person where id in (select id from person group by id having count(id)>1) and rowid not in (select min(rowid) from person group by id having count(*)>1)复制代码
  1. 查询表中重复记录(多个字段)
select * from tablename a where (a.seq,a.id) in (select seq,id from tablename group by sql,id having count(*)>1)复制代码
  1. 删除表中重复记录(多个字段),只保留rowid最小的字段
delete from tablename a where (a.id,a.seq) in (select id,sql from tablename group by id,sql having count(*)>1) and rowid not in (select min(rowid) from tablename group by id,sql having count(*)>1)复制代码
  1. 查找表中重复数据,不包含rowid最小记录
select * from tablename a where (a.id,a.seq) in (select id,seq from tablename group by id,seq having count(*)>1) and rowid not in (select min(rowid) from tablename group by id,seq having count(*)>1)复制代码