【问题标题】:Update table column Where更新表列 Where
【发布时间】:2012-12-29 03:08:39
【问题描述】:

我有productinfo 表和product_temp 表。 我想更新表productinfo 的字段UpdateDate 其中productinfo.ProductID = productinfo_temp.ProductID

但下面的代码不起作用。

UPDATE productinfo a 
SET UpdateDate = productinfo_temp.UpdateDate 
    WHERE EXISTS(SELECT NULL FROM productinfo_temp b WHERE a.ProductID = b.ProductID)

【问题讨论】:

    标签: mysql sql join sql-update


    【解决方案1】:

    试试这个

    UPDATE productinfo a JOIN productinfo_temp b ON a.ProductID = b.ProductID
    SET a.UpdateDate = b.UpdateDate 
    

    【讨论】:

      【解决方案2】:

      使用UPDATE with JOIN

      UPDATE  productinfo a  
              INNER JOIN productinfo_temp b
                  ON a.ProductID = b.ProductID
      SET     a.UpdateDate = b.UpdateDate 
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-04-13
        • 2019-06-04
        相关资源
        最近更新 更多