I have a table contacts that contains columns index_id,name,address,phone1,phone2,phone3.
Due to poor management over the years, there are 212,019 rows out of 484,097 where phone1 is not unique. However, each record is a unique record.
I need phone1 to be unique, but I don’t want to lose 212k records doing it.
phone3 is a new column that is null for each record. My thought is I could simply move* VALUES(phone1) into phone3
I tried this query not understanding that ON DUPLICATE UPDATE would simply update the previously existing record.
insert into tmp select * from contacts
on duplicate key update phone3 = values(phone1);
I tried just moving* all the duplicates over to phone3 with
update contacts
set phone3 = phone1
where count(phone3) > 1;
But that’s an invalid use of group function.
I’m thinking this is going to require a subquery, that’s where I start to get confused. Are there any suggestions?
*move is to mean that the data would no longer be in phone1 but rather would be in phone3. as in phone1 = NULL and phone3 = data
This will move all duplicated phone1 to column phone3. Phone1 will be set to null for every record where there’s a duplicate: