I want to alter an existing MySQL table to enforce a uniqueness constraint, but the data in the table currently is not unique.
Is there a way to modify only the set of duplicated data while leaving the rest unaffected? I don't want to delete the offending records as the rest of the data in the table is valuable.
Example:
> SELECT id, email from my_table;
+--------------------------------------+----------------+
| id | email |
+--------------------------------------+----------------+
| 070d5788-428e-4444-bd15-00b60f335bd6 | test@email.com |
| 0a81ae48-8900-4444-86da-d9418ea2ca00 | test@email.com |
| 0df1e66d-0053-4444-9774-c7daf5652d54 | test@email.com |
| 130fce57-178e-4444-b2cb-1c5c2c29fe07 | test@email.com |
...
SQL to run:
ALTER TABLE my_table ADD UNIQUE (email);