有两个数据表,分别是(tbA [a1,a2] tbB [b1,B2]),下面是具体数据tba
A1 A2
---------------------
211-09010001 70202100-043
211-09010001 70202100-042tbB
B1 B2
---------------------
211-09010001 70202100-040
211-09010001 70202100-042
211-09010001 70202100-043
用语句查出tbB中不存在于tbA的记录(按上面的数据应该只显示tbB的第一条记录.因为只有这一条不存在于tbA表中).
A1 A2
---------------------
211-09010001 70202100-043
211-09010001 70202100-042tbB
B1 B2
---------------------
211-09010001 70202100-040
211-09010001 70202100-042
211-09010001 70202100-043
用语句查出tbB中不存在于tbA的记录(按上面的数据应该只显示tbB的第一条记录.因为只有这一条不存在于tbA表中).
from tbB b
where not exists (select *
from tbA a
where a.a1 = b.b1
and a.a2 = b.b2)
minus
select A1,A2 from TbA
select * from tbB b where b.B1 not in(select a.A1 from tbA a where a.a1=b.b1) and b.b2 not in
(select a.a2 from tbA a where a.a2=b.b2)
where not exists
(select * from tbA a
where a.a1 = b.b1
and a.a2 = b.b2)
minus
select A1,A2 from TbA
insert into tba values('211-09010001','70202100-043');
insert into tba values('211-09010001','70202100-042');create table tbb (b1 varchar2(20),b2 varchar2(20));
insert into tbb values('211-09010001','70202100-040');
insert into tbb values('211-09010001','70202100-042');
insert into tbb values('211-09010001','70202100-043');
commit;
select *
from tbB b
where not exists (select *
from tbA a
where a.a1 = b.b1
and a.a2 = b.b2) select *
from tbb
minus
select * from tba;
实在不算高难度啊
顶一下,其实就是tbB与tbA的差集
一个minus就解决了
minus
select A1,A2 from TbA
就这样