I need to find and delete duplicates from within a table, yet keep a record of the IDs of the records being deleted and add them to a ‘deleted_ids’ field.
For example, here’s part of a table I have currently:
+--------+-------------------------------------------------------+
| Id | Name |
+--------+-------------------------------------------------------+
| 9627 | John Smith |
| 9657 | John Smith |
| 24455 | John Smith |
| 67435 | John Smith |
+--------+-------------------------------------------------------+
The result I’d like to achieve is:
+--------+-----------------------------+-------------------------+
| Id | Name | Deleted_Ids |
+--------+-----------------------------+-------------------------+
| 9627 | John Smith | 9657,24455,67435 |
+--------+-----------------------------+-------------------------+
I’m open to any practical approach, if anyone can provide a solution or give suggestions I’d really appreciate it.
Thanks,
Paul
If you want to proceed like this, here is a simple way.
Do it all in one transaction to be sure.
If there could be an entry of
'John Smith'intbl_delalready, you have to check andUPDATEto add the deleted ids instead.But I think Veseliq has a vaid point.