内部加入更新

时间:2014-10-01 08:40:49

标签: mysql sql

我目前正试图弄清楚如何让它发挥作用。

    UPDATE 
systems AS C 
SET C.nulled = '1' 
FROM systems 
INNER JOIN systems AS P 
ON C.nullif = P.sid 
WHERE P.status = 1

如果我正确地做到这一点,我不是100%。如果P.sid等于C中的nullif列,我想将C.null更新为1.

2 个答案:

答案 0 :(得分:2)

这是正确的语法

UPDATE systems AS C 
  INNER JOIN systems AS P 
  ON C.nullif = P.sid 
SET C.nulled = '1' 
WHERE P.status = 1

答案 1 :(得分:1)

正确的语法:

UPDATE `systems` AS `C`
INNER JOIN `systems` AS `P`
    ON `C`.`nullif`=`P`.`sid`
SET `C`.`nulled`='1' 
WHERE `P`.`status`=1