【发布时间】:2011-12-19 21:41:55
【问题描述】:
需要帮助构建查询以替换与第二个表匹配的表中的字段。
表1
city
表2
city | code
我需要用与城市字段匹配的 table2 的代码替换 table1 上所有出现的城市
【问题讨论】:
需要帮助构建查询以替换与第二个表匹配的表中的字段。
表1
city
表2
city | code
我需要用与城市字段匹配的 table2 的代码替换 table1 上所有出现的城市
【问题讨论】:
我认为它会是这样的:
update table1 t1 set t1.city = t2.code from table2 t2 where t1.city = t2.城市
【讨论】:
其实不需要替换:
UPDATE table1 JOIN table2 ON table1.city = table2.city SET table1.code = table2.code
【讨论】: