Update specific records of MySQL table

前端 未结 5 1337
没有蜡笔的小新
没有蜡笔的小新 2021-01-13 00:41

I am dealing with phone system and have to work with multiple service vendors. For one vendor I have a MySQL table country_codes like this -

--         


        
5条回答
  •  执笔经年
    2021-01-13 01:26

    You can create a table with countries only, i.e.:

    INSERT INTO countries (country_code,country)
    SELECT country_code,country FROM country_codes WHERE country_code=0
    

    Then you can easily update your table

    UPDATE country_codes cc, countries c
    SET cc.country_code = c.country_code
    WHERE LOCATE(c.country,cc.country)=1 AND cc.country_code=0
    

    I haven't tested this, but I believe you can get the point.

提交回复
热议问题