With SQL statements, delete duplicates only keep one

Source: Internet
Author: User

In the original text with the SQL statement, delete duplicates only keep one

in thousands of records, there are some same records, how can you use SQL statements, delete duplicates1, duplicate records in the lookup table are judged by a single field (Peopleid) .Select *  frompeoplewherePeopleidinch(SelectPeopleid fromPeopleGroup  byPeopleid having Count(Peopleid)> 1) 2, delete redundant records in the table, duplicate records are judged by a single field (Peopleid), leaving only the smallest rowID recordsDelete  frompeoplewherePeoplenameinch(SelectPeoplename fromPeopleGroup  byPeoplename having Count(Peoplename)> 1)  andPeopleid not inch(Select min(Peopleid) fromPeopleGroup  byPeoplename having Count(Peoplename)>1) 3, finding extra duplicate records in a table (multiple fields)Select *  fromVitae awhere(A.PEOPLEID,A.SEQ)inch(SelectPeopleid,seq fromVitaeGroup  byPeopleid,seq having Count(*)> 1) 4, delete extra duplicate records (multiple fields) in the table, leaving only the record with ROWID minimumDelete  fromVitae awhere(A.PEOPLEID,A.SEQ)inch(SelectPeopleid,seq fromVitaeGroup  byPeopleid,seq having Count(*)> 1)  androwID not inch(Select min(ROWID) fromVitaeGroup  byPeopleid,seq having Count(*)>1) 5, find redundant duplicate records (multiple fields) in the table, and do not contain ROWID minimum recordsSelect *  fromVitae awhere(A.PEOPLEID,A.SEQ)inch(SelectPeopleid,seq fromVitaeGroup  byPeopleid,seq having Count(*)> 1)  androwID not inch(Select min(ROWID) fromVitaeGroup  byPeopleid,seq having Count(*)>1)   6. Remove the first bit to the left of a field:UpdateTableNameSet [Title]=right([Title],(Len([Title])-1))whereTitle like 'Village%'7. Eliminate the first bit on the right side of a field:UpdateTableNameSet [Title]=left([Title],(Len([Title])-1))whereTitle like '% Village'8false Delete extra duplicate records (multiple fields) in the table, not including ROWID minimum recordsUpdateVitaeSetIspass=-1wherePeopleidinch(SelectPeopleid fromVitaeGroup  byPeopleid

With SQL statements, delete duplicates only keep one

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.