SQL: How to update duplicates at separate table?
问题 I have 2 tables: Table1: id1 | id2 1 | a 2 | a 3 | a 4 | b 5 | b Table2: data | id1 ... | 1 ... | 2 ... | 2 ... | 3 ... | 4 ... | 5 At Table1 I should have unique association of id1->id2, for some unknown reason it's not. I need to fix it and add unique constraint. I need to leave only one to one relation at Table1 and update duplicated ids at Table2 only with that id which is left at Table1 . As the result I should have: Table1: id1 | id2 1 | a 4 | b Table2: data | id1 ... | 1 ... | 1 ... |