Scenario: I have few duplicate contacts in the table. Duplicates are identified, I can simply delete them, but the problem is that I do not want to lose the data that the duplicate may have, but the original is not. Any tips?
Sample data:
ID Name Email School Dupe_Flag Key 1 AAA a@a X 1 2 AAB JKL 1 3 BBB b@b MNO X 2 4 BBC 2
Required Conclusion:
ID Name Email School Dupe_Flag Key 1 AAA a@a X 1 2 AAB a@a JKL 1 3 BBB b@b MNO X 2 4 BBC b@b MNO 2
How are 2 records related ?: Both of them have the same key value with only one column with Dupe_Flag SET, which is a duplicate column.
In the above case, ID 1 will be deleted, but the email address from ID 1 must be applied to ID 2.
What is data ?: I have several hundred rows and several 100 duplicates. The UPDATE statement for each row is cumbersome and impossible.
Business rules for determining which data takes precedence:
If the column from the original / good record (Dupe_Flag is NOT set) does not have data, and if there is data in the corresponding Dupe column (with the same key value), then this original record column should be updated.
Any help / script really appreciated! Thanks guys:)
mysql duplicates
Thinkcode
source share