I have a table with a few thousand rows. The table contains two columns, name and email. I have several duplicate rows, for example:
- John Smith | john@smith.com
- John Smith | john@smith.com
- Erica Smith | erica@smith.com
- Erica Smith | erica@smith.com
What would be the easiest way to delete all duplicate results. For example, such that the table’s content would = SELECT name, DISTINCT(email) FROM table.
You could pretty easily do this by selecting that query into another table, then renaming it to replace the original.
Note that this
CREATEshould be adjusted to your actual table format. I added the unique key on the email field as a suggestion on how you would prevent duplicates in the first place.Alternatively, you could loop over this
Which would delete one duplicate record per call. The importance of the limit is to not remove both rows for any duplicate