我有一张桌子
城市名称表(城市表)

idcity  |   cityname     |  statename  |    codenumber
   1    |   Los Angeles  |   state2    |     ...
   2    |   New York     |   state3    |     ...
   3    |   New Jersey   |   state3    |     ...

代码城市表(代码表)
  id |  city     | codenumber
   1 |  angeles  |   031
   2 |  york     |   064
   3 |  jersey   |   075

如何SET or INSERT or UPDATE data 'codenumber' FROM 'codetable' fields INTO 'codenumber' column FROM citytable WHERE 'city' FROM codetable LIKE '%cityname%' FROM 'citytable'
谢谢你的帮助。

最佳答案

使用UPDATE with join

UPDATE  cityTable a
        INNER JOIN codeTable b
            ON a.ID = b.ID
SET     a.codeNumber = b.codeNumber

但我怀疑IDAUTO_INCREMENTed列,如果是的话,
UPDATE  cityTable a
        INNER JOIN codeTable b
            ON a.cityName LIKE CONCAT('%', b.city,'%')
SET     a.codeNumber = b.codeNumber

关于mysql - 如何更新MySQL SET值在某些列内容(如其他表列内容)中,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14403415/

10-11 06:34