【问题标题】:Copying One column from table to another table that has matching variables in another column将一列从表复制到另一列中具有匹配变量的另一表
【发布时间】:2014-10-18 22:03:15
【问题描述】:

我希望我能解释清楚,哈哈。

我正在尝试将两个表中与 hats_new.name 匹配的变量从一个 hats_old.red 复制到 hats_new.red,如果它们不匹配,那么我需要它什么都不做,因此它不会将值设为空或将其设置为0.

这是据我所知。这更改为 0,我试图避免并且无法弄清楚其余部分。 这是给Mysql的

谢谢

UPDATE hats_new 
SET hats_new.red = (
    SELECT hats_old.red
    FROM hats_old
    WHERE hats_old.name = hats_new.name LIMIT 1
);

【问题讨论】:

    标签: mysql multiple-columns copying exact-match


    【解决方案1】:

    updatejoin 应该可以解决问题:

    UPDATE hats_new hn
    JOIN   hats_old ho ON hn.name = oh.name
    SET    hn.red = ho.red
    

    【讨论】:

      猜你喜欢
      • 2015-06-07
      • 1970-01-01
      • 2012-07-21
      • 1970-01-01
      • 1970-01-01
      • 2010-10-05
      • 1970-01-01
      • 2012-08-12
      • 2017-11-02
      相关资源
      最近更新 更多