TableA 有列 AccountNum 和 RoutingNum
TableB 还有列 AccountNum 和 RoutingNum
表 B 更值得信赖。因此,我想找出表 A 中的所有记录是否存在于表 B 中。如果不是,哪些记录不匹配。
这是否走在正确的轨道上?您的解决方案将不胜感激。
select *
from TableA a
where a.AccountNum not in (select b.AccountNum from TableB)
您可以使用not exists
.以下查询为您提供了tablea
中无法在tableb
中找到的所有记录:
select a.*
from tablea a
where not exists (
select 1
from tableb b
where a.accountNum = b.accountNum and a.routingNum = b.routingNum
)
这假设您希望在两列上匹配(这是您的描述所建议的(。您可以调整子查询中的where
条件,使其仅匹配一列。