方法1:
update people s set city_name = (select name from city where code = s.city_code);
1,代码对应的城市更新,对应错误的更正;
2,city表中没有的城市,在people表里全被更新为null。
方法2:
update people s, city c set s.city_name = c.name where s.city_code = c.code;
1,代码对应的城市更新,对应错误的更正;
2,city表中没有的城市,在people表里保持原数据,不会被清空。
方法3:
UPDATE people LEFT JOIN city ON people.city_code=city.code SET people.city_name=city.name;
结果跟方法1一样
总结
建议用方法2比较保险