[英]Delete intersection between two tables in SQL Server
我想从 #temp_scoring 中删除匹配的帐户(匹配 ID 和 acct_num),但最终删除了表 #temp_scoring 中的所有行。 这是代码:
delete from #temp_scoring
where exists (
select * from #temp_edu te
where te.ID = ID
and te.acct_num = acct_num)
作为旁注,我会为 #temp_scoring 创建一个别名,但是当我这样做时它给了我一个语法错误。
DELETE s
FROM
#temp_scoring s
INNER JOIN #temp_edu te
ON s.ID = te.ID
AND s.acct_num = te.acct_num
您可以使用 join 进行删除
您的问题是列名:
delete from #temp_scoring
where exists (
select * from #temp_edu te
where te.ID = ID --- Here ID means te.ID
and te.acct_num = acct_num -- and acct_num means te.acct_num
)
需要明确的是, ID = te.ID
因为这是最近的封闭范围的ID
。
你可能想要这个
delete ts
from #temp_scoring ts
where exists (
select 1
from #temp_edu te
where te.ID = ts.ID
and te.acct_num = ts.acct_num
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.