I have these two tables:
TableA
+----+----------+----------+
| Id | TableBId | TableCId |
+----+----------+----------+
| 1 | 1 | 10 |
| 2 | 2 | 11 |
| 3 | 3 | 12 |
| 4 | 4 | 13 |
| 5 | 5 | 14 |
TableC
+-----+------+
| Id | Name |
+-----+------+
| 10 | John |
| 11 | John |
| 12 | Ann |
| 13 | Mark |
| 14 | Mark |
+-----+------+
How can I remove duplicates records from TableC
with keep one and change id in TableA
?
Finally, the tables should look like:
TableA
+----+----------+----------+
| Id | TableBId | TableCId |
+----+----------+----------+
| 1 | 1 | 10 |
| 2 | 2 | 10 |
| 3 | 3 | 12 |
| 4 | 4 | 13 |
| 5 | 5 | 13 |
TableC
+-----+------+
| Id | Name |
+-----+------+
| 10 | John |
| 12 | Ann |
| 13 | Mark |
+-----+------+
At first, I need to change the ids, then remove the duplicates.