MySQL deletes duplicate records in a table

Source: Internet
Author: User

Version: 5.0.22-community-nt.

1. Create a temporary table folder_tmp for the table folder

Create table folder_tmp as select * from folder group by serverIp, userId, name, path;

After grouping by serverIp, userId, name, and path, the data in front of the primary key id is left in the folder_tmp table.

2. Delete the original table

Drop table folder

3. rename a table

Alter table folder_tmp rename folder

4. Do not finish creating foreign keys and indexes and primary keys. Because the temporary table created in step 1 does not contain the Foreign keys, indexes, and primary keys of the original table.

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.