Delete duplicate data records in a database, find duplicate records, find non-duplicate records __ Database

Source: Internet
Author: User


Delete duplicate records (keep last duplicate data):

Delete table where primary key ID not in (select MAX ([primary key ID]) from table group by (duplicate field one + duplicate field two))

Delete duplicate records (keep first duplicate data):

Delete table where primary key ID not in (select min ([primary key ID]) from table group by (duplicate field one + duplicate field two))

Finds all duplicate data for a database that does not include the last row of duplicate data:

SELECT * FROM table where primary key ID not in (select MAX ([primary key ID]) from table group by (duplicate field one + duplicate field two))

Finds all duplicate data for a database that does not include duplicate data from the first row:

SELECT * FROM table where primary key ID not in (select min ([primary key ID]) from table group by (duplicate field one + duplicate field two))

Find the last line of duplicate data:

SELECT * FROM table where primary key ID in (select MAX ([W_SN]) from table group by (duplicate field one + duplicate field II))

Find the first row of duplicate data:

SELECT * FROM table where primary key ID in (select min ([W_SN]) from table group by (duplicate field one + duplicate field II))

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.