开发者

You can't specify target table 'A' for update in FROM clause

开发者 https://www.devze.com 2023-02-25 11:10 出处:网络
This is my request > DELETE FROM A WHERE id in (Select > id From ALeft Join B on开发者_Python百科 A.id=B.id

This is my request

> DELETE FROM A WHERE id in (    Select
> id From A    Left Join B on开发者_Python百科 A.id=B.id 
> Where B.id is null )

When I execute this I have this error

You can't specify target table 'A' for update in FROM clause


Maybe you could do it like this instead?

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


You want to delete all records from table A that don't have a matching id in table B?

How about this:

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


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

精彩评论

暂无评论...
验证码 换一张
取 消