简体   繁体   English

sql更新不起作用

[英]sql update does not work

This works 这有效

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

However, it would like to update productinfo table from that result 但是,它想根据该结果更新productinfo表

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

But it does not works. 但这是行不通的。 What is wrong with UPDATE? UPDATE有什么问题? Here is error 这是错误

#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

Try: 尝试:

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

remove FROM clause. 删除 FROM子句。

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

or simply use this one using LEFT JOIN 或直接使用LEFT JOIN来使用

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

I'm getting in too! 我也要进去!

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM