【问题标题】:MYSQL join + replace?MYSQL加入+替换?
【发布时间】:2011-12-19 21:41:55
【问题描述】:

需要帮助构建查询以替换与第二个表匹配的表中的字段。

表1

city

表2

city | code

我需要用与城市字段匹配的 table2 的代码替换 table1 上所有出现的城市

【问题讨论】:

    标签: mysql join replace


    【解决方案1】:

    我认为它会是这样的:

    update table1 t1 set t1.city = t2.code from table2 t2 where t1.city = t2.城市

    【讨论】:

      【解决方案2】:

      其实不需要替换:

      UPDATE table1 JOIN table2 ON table1.city = table2.city SET table1.code = table2.code
      

      【讨论】:

        猜你喜欢
        • 2013-12-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-02-25
        • 2015-08-07
        • 2012-03-27
        • 1970-01-01
        相关资源
        最近更新 更多