Hi,

Does anyone have a script that deletes duplicate mysql records (that actually works)?

I've found a few suggestions in this forum, and others, but they don't work.

Also, is it really necessary to add an "id field" which increments, to do this "deleting of the duplicates?" I went ahead and added an id field to my table, in anticipation that I'd need this; but you'd think there is a way to delete the dups without this.

Thanks!

    That's the whole point of unique fields...it keeps dupliate rows OUT of the database.

    And yes, you'll need an ID if you want to delete rows. You typically will delete by ID, cause it will be unique.

    Loop through your DB. Compare rows. If you run across a duplicate row, delete it by ID. Simple enough.

      No... sorry... I wanted a script, as in

      Dear mySQL,

      Hello, would you please automatically delete ALL duplicate rows, since there are many many duplications, and also because I don't want to manually delete rows one by one.

      Thank you,

      Your Friend,

      Noerd

      e.g. delete * from mytable where row? \= dup(e£(&%);

      or something that looks like that! :-)

        Well, if they've all got different unique ID's, then by definition they're not duplicates.

        Here's a Brute-Force-and-Bloody-Ignorance method.

        SELECT DISTINCT

        • from [tabletostrip]

          Read those all into PHP.

          Mass genocide: DELETE FROM [tabletostrip]

          Now have PHP reinsert the previously-selected data.

          Write a Reply...