2013-01-08 96 views
0

這工作SQL更新不起作用

SELECT * FROM productinfo a 
WHERE NOT EXISTS(SELECT NULL 
       FROM productinfo_temp b 
          WHERE a.ProductID = b.ProductID) 

但是,它想從該結果

UPDATE a SET Deleted = '1' FROM productinfo a 
    WHERE NOT EXISTS(SELECT NULL 
        FROM productinfo_temp b 
           WHERE a.ProductID = b.ProductID) 

更新productinfo表,但它沒有工作。 UPDATE有什麼問題? 這是錯誤

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM productinfo a WHERE NOT EXISTS(SELECT NULL FROM productinfo' at line 1 

回答

2

嘗試:

UPDATE productinfo a SET Deleted = '1' 
    WHERE NOT EXISTS(SELECT NULL 
        FROM productinfo_temp b 
           WHERE a.ProductID = b.ProductID) 
2

刪除FROM條款。

UPDATE productinfo a 
SET Deleted = '1' 
WHERE NOT EXISTS(SELECT NULL 
       FROM productinfo_temp b 
       WHERE a.ProductID = b.ProductID) 

或者乾脆用這一個使用LEFT JOIN

UPDATE productinfo a 
     LEFT JOIN productinfo_temp b 
      ON a.ProductID = b.ProductID 
SET  a.Deleted = 1 
WHERE b.ProductID IS NULL 
1

我得到的太多!

UPDATE a SET Deleted = '1' 
WHERE NOT EXISTS(SELECT NULL 
FROM productinfo_temp b 
WHERE a.ProductID = b.ProductID)