Delete MySQL Duplicates: Keep One Record

You can use the following steps to remove duplicate values and keep only one:

  1. First, use the SELECT DISTINCT query to find all unique values.
  2. Retrieve unique records from your_table.
  3. Create a temporary table and insert non-duplicate data into it.
  4. Create a temporary table with the same structure as your_table and insert all unique rows from your_table into the temporary table.
  5. Delete the original table.
  6. Delete the table named “your_table”.
  7. Rename the temporary table to the name of the original table.
  8. Change the table name from tmp_table to your_table.

Now, your table will only keep a single unique piece of data. Please make sure to backup your data before carrying out this operation to prevent any accidental loss of data.

bannerAds