Query SQL statements and delete duplicate records

1, the lookup table excess <wiz_tmp_highlight_tag class = "cm-searching"> repeatedly recorded, <wiz_tmp_highlight_tag class = "cm-searching"> repeatedly recorded is judged based on a single field (Id)
 
select * from 表 where Id in (select Id from 表 group by Id having count(Id) > 1)
 
2, the table remove excess <wiz_tmp_highlight_tag class = "cm-searching"> repeatedly recorded, <wiz_tmp_highlight_tag class = "cm-searching"> repeatedly recorded is judged based on a single field (Id), leaving only the smallest recording rowid
 
DELETE from 表 WHERE (id) IN ( SELECT id FROM 表 GROUP BY id HAVING COUNT(id) > 1) AND ROWID NOT IN (SELECT MIN(ROWID) FROM 表 GROUP BY id HAVING COUNT(*) > 1);
 
3, to find the excess <wiz_tmp_highlight_tag class = "cm-searching"> recorded repeatedly (multiple fields) in the table
 
select * from 表 a where (a.Id,a.seq) in(select Id,seq from 表 group by Id,seq having count(*) > 1)
 
4, the table remove excess <wiz_tmp_highlight_tag class = "cm-searching"> recorded repeatedly (more than one field), leaving only the smallest recording rowid
 
delete from 表 a where (a.Id,a.seq) in (select Id,seq from 表 group by Id,seq having count(*) > 1) and rowid not in (select min(rowid) from 表 group by Id,seq having count(*)>1)
 
5, find excess <wiz_tmp_highlight_tag class = "cm-searching"> recorded repeatedly (multiple fields) in the table does not include the smallest recording rowid
 
select * from 表 a where (a.Id,a.seq) in (select Id,seq from 表 group by Id,seq having count(*) > 1) and rowid not in (select min(rowid) from 表 group by Id,seq having count(*)>1)

 

Guess you like

Origin www.cnblogs.com/shelly0307/p/10965844.html