MySQL Delete duplicate records

Source: Internet
Author: User
Tags mysql delete

The principle of MySQL deleting duplicate records is:

After placing the column to be compared to group by, remove the minimum value of the primary key, and then delete the row that is not in the primary key of the temporary table

The command line format is as follows

Delete from the users where ID not in (the Select ID from the (select min (id) from the Users group by Name,sex) as TMP);

The columns that need to be compared are name and sex, the ID is removed and the ID is removed from the users table to see if the ID exists in the temporary table, and it is deleted if it does not exist.

MySQL Delete duplicate records

Related Article

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.