I'm adding a new column to my CountryCodes table, phoneCodes. I want to add each country's phone code based on the numericCode that already exists in the table. Is there a way to do this without doing a SET for each country? It seems inefficient to do:
CountryCodes
phoneCodes
numericCode
UPDATE TABLE `CountryCodes` SET `phoneCode` = 1 WHERE `numericCode = 840 ... /* Do this for each country?*/
You can use a case expression:
case
update table countrycodes set phonecode = (case when numericCode = 840 then 1 . . . end) where numericCode in (840, . . .);
2.1m questions
2.1m answers
60 comments
57.0k users