select * from table1 t1,tabel2 t2 where t1.a<>t2.b
create table ll_a( a varchar2(10) )create table ll_b ( b VARCHAR2(20) )begin insert into ll_a values('aa'); insert into ll_a values('bb'); insert into ll_a values('cc');insert into ll_b values('aa'); insert into ll_b values('bb'); insert into ll_b values('dd'); end;select * from ll_a ,ll_b where ll_a.a<>ll_b.b--结果 bb aa cc aa aa bb cc bb aa dd bb dd cc dd ----结果不对么 要么你给出数据 给出结果 看你上面的描述,我觉得我的结果没问题啊
select * from table1 where table1.a not in (select table2.b from table2) union all select * from table2 where table2.b not in (select table1.a from table1)
--建立测试表1 create table test1 (id number); --建立测试表1 create table test2 (id number); --插入测试数据 insert into test1 values(1); insert into test1 values(2); insert into test1 values(3); insert into test1 values(4); --插入测试数据 insert into test2 values(1); insert into test2 values(2); insert into test2 values(5); insert into test2 values(6); --执行语句,察看结果 select id from test1 union select id from test2 minus select a.id from test1 a,test2 b where a.id = b.id; ID ---------- 3 4 5 6
from table1 t1,tabel2 t2
where t1.a<>t2.b
a varchar2(10)
)create table ll_b
(
b VARCHAR2(20)
)begin
insert into ll_a values('aa');
insert into ll_a values('bb');
insert into ll_a values('cc');insert into ll_b values('aa');
insert into ll_b values('bb');
insert into ll_b values('dd');
end;select *
from ll_a ,ll_b
where ll_a.a<>ll_b.b--结果
bb aa
cc aa
aa bb
cc bb
aa dd
bb dd
cc dd
----结果不对么
要么你给出数据
给出结果
看你上面的描述,我觉得我的结果没问题啊
我的回复中,有数据
如果是我列的数据
结果是什么样呢我不知道你的表中数据什么样
你要的结果又是什么样别人很难理解你的意思
你给出数据
给出结果
别人理解会容易些
而且和你的想法不会有太大出入
2
3
4
table2里有字段b 有数据
3
4
56
7
对于上述几条数据(实际库中好多),就是过虑出来table1.a=4的记录来 不知道 我描述清楚了没有
from table1
where table1.a not in (select table2.b from table2)
union all
select *
from table2
where table2.b not in (select table1.a from table1)
为什么是4
4在两个表中都有
而且3也有
为什么不一起出来
--是这样的。。table1里有字段a 里面有数据
2
3
4
table2里有字段b 有数据
3
4
56
7
对于上述几条数据(实际库中好多),就是过虑出来table1.a=4的记录来 不知道 我描述清楚了没有
minus
select b from b
create table test1
(id number);
--建立测试表1
create table test2
(id number);
--插入测试数据
insert into test1 values(1);
insert into test1 values(2);
insert into test1 values(3);
insert into test1 values(4);
--插入测试数据
insert into test2 values(1);
insert into test2 values(2);
insert into test2 values(5);
insert into test2 values(6);
--执行语句,察看结果
select id
from test1
union
select id
from test2
minus
select a.id
from test1 a,test2 b
where a.id = b.id; ID
----------
3
4
5
6