I have a parent table 'policy' that contains multiple duplicate rows, in the sense that there are 2 fields which together constitutes a duplicate (i.e. policy_number and provider_id).
I also have a child table 'branch_policy' that contains child records for the duplicate parent rows (there is another child table of 'policy', but I'm hoping I could just apply the same solution to the 2nd child table as well).
Before I delete the duplicate parent rows, I want to re-parent the child records of the duplicate parent records to point one parent record, in order to safely delete the duplicate parent records.
E.g.:
policy table:
id policy_number provider_id originating_branch
--------------------------------------------------
1 123 1 1
2 123 1 2
branch_policy table:
id policy_id
--------------
1 1
2 2
I would like the 2nd record of branch_policy to be set to policy_id = 1, then delete policy record with id 2, so that I end with
policy table:
id policy_number provider_id originating_branch
--------------------------------------------------
1 123 1 1
branch_policy table:
id policy_id
--------------
1 1
2 1
Please note that it's not important which duplicate parent record is selected as the 'survivor'.
I hope that's clear!