SQL:选择要通过连接删除的行
场景:
假设我有两个表格,TableA和TableB。 TableB的主键是单列(BId),并且是TableA中的外键列。
在我的情况下,我想删除TableB中与TableB中的特定行链接的所有行:我可以通过连接来实现吗? 删除从连接拉入的所有行?
DELETE FROM TableA
FROM
TableA a
INNER JOIN TableB b
ON b.BId = a.BId
AND [my filter condition]
还是我被迫这样做:
DELETE FROM TableA
WHERE
BId IN (SELECT BId FROM TableB WHERE [my filter condition])
我想问的原因是,在我看来,在处理大型表格时,第一种选择会更加有效。
谢谢!
DELETE TableA
FROM TableA a
INNER JOIN TableB b
ON b.Bid = a.Bid
AND [my filter condition]
应该管用
我会用这个语法
Delete a
from TableA a
Inner Join TableB b
on a.BId = b.BId
WHERE [filter condition]
是的你可以。 示例:
DELETE TableA
FROM TableA AS a
INNER JOIN TableB AS b
ON a.BId = b.BId
WHERE [filter condition]
链接地址: http://www.djcxy.com/p/94219.html
上一篇: SQL: Selecting rows to delete via joins
下一篇: SQL update from one Table to another based on a ID match