Sql Query 帮助从两个表中获取不匹配的记录 [英] Sql Query help to get non matching records from two tables
本文介绍了Sql Query 帮助从两个表中获取不匹配的记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图从 2 个表中获取不匹配的记录
I am trying to get non matching records from 2 tables
例如
TableA
ID Account
1 Acc1
2 Acc2
3 Acc3
TableB
Opp Accountid
Opp1 1
Opp2 2
Opp3 4
我需要知道 TableB 中存在哪个 accountid 而 TableA 中不存在.如果有人可以提供此查询,那就太好了.
I need to know which accountid is present in TableB but not in TableA. It would be wonderful if someone could provide this query.
需要的记录是tableB的Opp3
Required record would be Opp3 of tableB
谢谢
普拉迪
推荐答案
create table #one (id int,acc nvarchar(25))
insert into #one (id , acc) values(1,'one')
insert into #one (id , acc) values(2,'two')
insert into #one (id , acc) values(3,'three')
create table #two (acct nvarchar(25),ids int)
insert into #two (acct,ids) values('one',1)
insert into #two (acct,ids) values('two',3)
insert into #two (acct,ids) values('four',4)
select ids from #two EXCEPT select id from #one
drop table #one
drop table #two
测试这个
这篇关于Sql Query 帮助从两个表中获取不匹配的记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文