SQL更新不起作用

时间:2013-01-08 02:25:14

标签: mysql sql sql-update

这有效

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)

但它不起作用。 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

3 个答案:

答案 0 :(得分:2)

尝试:

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

答案 1 :(得分: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

答案 2 :(得分:1)

我也进来了!

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