Version 2

Remove duplicate entries / rows a mySQL database table – DeDupe

Before you start – backup your table, do an export with phpmyadmin.

Step 1: Move the non duplicates (unique tuples) into a temporary table

CREATE TABLE new_table AS
SELECT * FROM old_table WHERE 1 GROUP BY [COLUMN TO remove duplicates BY];

Step 2: delete delete the old table
We no longer need the table with all the duplicate entries, so drop it!

DROP TABLE old_table;

Step 3: rename the new_table to the name of the old_table

RENAME

TABLE new_table TO old_table;

Now you can fix that buggy code thats causing duplicate entries.

Just use “insert IGNORE into ….” to prevent duplicate entries, or add an “ON DUPLICATE KEY UPDATE …” at the end of your mysql query.

Go here to learn more about this:

http://dev.mysql.com/doc/refman/5.0/en/insert.html

Comments are closed.

  • Categories

  • Client testimonials

    "There is nothing that Intricate Web can't do. I came to Intricate with the idea of creating a very simple, blog-based site. By the time the site was finished, we had created an interactive, dynamic website that allowed us to spread word about our business quickly and effectively. And, Intricate completed the site on time and for less than a quarter of the cost of other web companies."
    Andrew Hunt | Scholars for Students
    <?php

    echo “Are you a Web Designer”;
    echo “Intricate Web can provide”;
    echo “White label Development”;
    echo “for your design firm.”;
    print “Outsource locally”;
    // comment - it’s our little secret.

    ?>
    © 2012 Intricate Web LLC
    Call us today! 401.709.4469