MySQL Delete duplicate records

Source: Internet
Author: User
Tags mysql delete

Solution 1:

Add Unique Index on your table:

ALTER IGNORE TABLE `TableA`   ADD UNIQUE INDEX (`member_id`, `quiz_num`, `question_num`, `answer_num`);

Solution 2:

ADD Primry key in your table and can easily remove duplicates from your table using below query:

DELETE FROM member  WHERE id IN (SELECT *              FROM (SELECT id FROM member                    GROUP BY member_id, quiz_num, question_num, answer_num HAVING (COUNT(*) > 1)                  ) AS A            );

Solution 3:

SELECT DISTINCT * INTO TableA_Verify FROM TableA;DROP TABLE TableA;RENAME TABLE TableA_Verify TO TableA;

Ref

Http://stackoverflow.com/questions/3311903/remove-duplicate-rows-in-mysql

Http://stackoverflow.com/questions/4685173/delete-all-duplicate-rows-except-for-one-in-mysql

Http://stackoverflow.com/questions/14046355/how-do-i-delete-all-the-duplicate-records-in-a-mysql-table-without-temp-tables

Http://www.databasejournal.com/features/mysql/article.php/10897_2201621_2/Deleting-Duplicate-Rows-in-a-MySQL-Database.htm

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.