Several methods of sharing SQL duplicate record query

 

Several methods of SQL repeated record query, friends who need it can refer to it

1. Find redundant duplicate records in the table, and duplicate records are judged based on a single field (peopleId)

code show as below:


select * from people
where peopleId in (select   peopleId from   people group by   peopleId having count

(peopleId) > 1)


2. Delete redundant duplicate records in the table. The duplicate records are judged based on a single field (peopleId), leaving only the record with the smallest rowid

code show as below:


delete from people
where peopleId in (select   peopleId from people group by   peopleId   having count

(peopleId) > 1)
and rowid not in (select min(rowid) from   people group by peopleId having count(peopleId

)>1)


3. Find redundant duplicate records (multiple fields) in the table

code show as below:


select * from vitae a
where (a.peopleId,a.seq) in   (select peopleId,seq from vitae group by peopleId,seq having

count(*) > 1)


4. Delete redundant duplicate records (multiple fields) in the table, leaving only the record with the smallest rowid

code show as below:


delete from vitae a
where (a.peopleId,a.seq) in   (select peopleId,seq from vitae group by peopleId,seq having

count(*) > 1)
and rowid not in (select min(rowid) from vitae group by peopleId,seq having count(*)>1)


5. Find redundant duplicate records (multiple fields) in the table, excluding the record with the smallest rowid

code show as below:


select * from vitae a
where (a.peopleId,a.seq) in   (select peopleId,seq from vitae group by peopleId,seq having

count(*) > 1)
and rowid not in (select min(rowid) from vitae group by peopleId,seq having count(*)>1)

Reposted from: Micro reading    https://www.weidianyuedu.com

Guess you like

Origin blog.csdn.net/weixin_45707610/article/details/131870703