在SQL中删除语句

Geo*_*rge 0 sql sql-delete

我有这些表:

  • Account(account-number (PK), branch-name (FK), balance)
  • Branch(branch-name (PK), branch-city, assets)

有人可以解释一下以下两个陈述之间的区别是什么?我在我的数据库中执行了它们,并且删除的行的结果是相同的.我错过了什么吗?

delete from account
where [branch-name] = 'London'
Run Code Online (Sandbox Code Playgroud)

delete from account
where [branch-name] in (select [branch-name]
                        from branch
                        where [branch-name]='London')
Run Code Online (Sandbox Code Playgroud)

Guf*_*ffa 5

区别在于第二个查询检查表中是否存在分支名称,然后在branch表中删除它account.

如果分支名称存在于account表中,但不存在于branch表中,则不会从account表中删除它.

第一个查询从account表中删除记录是否存在branch表中的分支.