Skip to content
Advertisement

Most efficient way to delete duplicate entries from MySQL tables

We have a table (let us call it originalTbl) that has duplicate entries that we want to delete. By duplicate I mean all values other than an AUTO INCREMENT index field are the same. One way to do this is to create a new table, like the existing table (let us call it uniqueTbl), and then have a query like:

Later on we will drop originalTbl and rename uniqueTbl to originalTbl.


However, I am looking for an alternate approach, that will delete the duplicate entries from originalTbl directly, without the overhead of first creating the uniqueTbl and then renaming it to originalTbl.

Advertisement

Answer

Unless you have very few duplicates, your method will be much, much faster. If you only have a few (say less than 1%), then you can try:

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement