Delete duplicate records

Source: Internet
Author: User

In thousands of records, there are some of the same records, how can you use SQL statements, delete duplicates? Thank you! 1, find redundant records in the table, duplicate records are judged by a single field (Peopleid)  select *  from people where peopleid in  (select  peopleid  from   People  group  by  peopleid  having  count (peopleId)   > 1)  2, delete redundant records in the table, repeat records are based on a single field (Peopleid) to judge, leaving only the ROWID minimum records  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, redundant duplicate records in lookup table (multiple fields)  select  * from vitae a where  (A.PEOPLEID,A.SEQ)  in   (select  Peopleid,seq from vitaE group by peopleid,seq  having count (*)  > 1)  4, Delete extra duplicate records (multiple fields) in the table, leaving only the ROWID minimum Records  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, redundant duplicate records in lookup table (multiple fields), does not contain ROWID minimum records  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)   For example, there is a field "name" in Table A, and the " Name "value may be the same,  now is the need to query out the table in the variousThe "name" value exists for duplicate entries;  select name,count (*)  from a group by name having  count (*)  > 1  If the gender is also the same as large as follows:  select name,sex,count (*)  From A  Group by name,sex having count (*)  > 1

Delete duplicate records

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.