我有一份商务中心列表。有时,数据输入人员没有所有信息,例如缺少城市名称,但其余信息是完整的。我还有另一张邮政编码表。我希望能够对那些没有城市的地址进行邮政编码查找,并获取城市名称。我正在 MySQL 中执行此操作。
我很难让 MySQL 正确执行此操作。不知道是语法问题还是MySQL逻辑错误。这就是我所拥有的:
update centers city
set centers.city = (
select zipcode_types.primary_city
from centers, zipcode_types
where centers.city="" and centers.zipcode=zip);
这是我从上述 MySQL 中得到的错误:
ERROR 1093 (HY000): You can't specify target table 'city' for update in FROM clause
我想做的是从 zipcode_types 表中找到城市名称并更新 中心表中缺少城市名称。感谢您的帮助,谢谢!
最佳答案
可以使用多表update syntax :
update centers
inner join zipcode_types on zipcode_types.zip = centers.zipcode
set centers.city = zipcode_types.primary_city
where centers.city='';
关于mysql - 如何让 MySQL 将第二个表的查询结果存储在第一个表中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13278330/