0

这有效

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

但是,它想根据该结果更新 productinfo 表

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

但它不起作用。更新有什么问题?这是错误

#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
4

3 回答 3

2

尝试:

UPDATE productinfo a SET Deleted = '1'
    WHERE NOT EXISTS(SELECT NULL 
                    FROM productinfo_temp b 
                                WHERE a.ProductID = b.ProductID)
于 2013-01-08T02:27:25.103 回答
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
于 2013-01-08T02:28:13.067 回答
1

我也进!

UPDATE a SET Deleted = '1'
WHERE NOT EXISTS(SELECT NULL 
FROM productinfo_temp  b
WHERE a.ProductID = b.ProductID)
于 2013-01-08T02:30:56.710 回答