我怎么做:
DELETE FROM foo WHERE id = 1 AND bar不包含id == 1
为了详细说明,我怎么能删除一行id = 1
,从表中foo
,仅如果没有在表中的一行bar
用id = 1
.
DELETE FROM foo WHERE id=1 AND NOT EXISTS (SELECT * FROM bar WHERE id=1)
我假设你的意思是foo和bar是表,如果它不存在于bar中你想要从foo中删除一条记录.
使用连接:
delete f from foo f left join bar b on f.id = b.id where f.id = 1 and b.id is null