您不能在FROM子句中为更新指定目标表'A'

时间:2011-04-12 08:21:20

标签: mysql sql sql-delete mysql-error-1093

这是我的要求

> DELETE FROM A WHERE id in (    Select
> id From A    Left Join B on A.id=B.id 
> Where B.id is null )

执行此操作时出现此错误

  

您无法为目标表'A'指定   在FROM子句中更新

3 个答案:

答案 0 :(得分:5)

也许你可以这样做吗?

DELETE FROM A WHERE id NOT IN (SELECT DISTINCT B.id FROM B);

答案 1 :(得分:1)

您想删除表A中表B中没有匹配ID的所有记录吗?

这个怎么样:

DELETE
FROM A
WHERE NOT EXISTS (select 1 from B where A.id = B.id);

答案 2 :(得分:1)

DELETE FROM A
WHERE NOT EXISTS (
    SELECT *
    FROM B
    WHERE content_id = B.content_id
)