日期:2014-05-17  浏览次数:20708 次

关于minus 求助!
假设有2张表A,B
A表有
NAME NO
DC 1
DW 2
DF 3
B表有
NAME NO
DC 1
DZ 6
DS 7

我要找出A表中没有的完整数据
 select B_NAME_NAME from B minus select A_NAME from A ;
这样查出来的是
NAME
DZ
DS
但是我想查出的是B表在A表中没有的全部数据
请问如何写?




------解决方案--------------------
是这样子的吗?
SQL code
 
SQL> create table a(name nvarchar2(30),no int);

Table created

SQL> create table b(name nvarchar2(30),no int);

Table created

SQL>
SQL> insert into a
2  select 'dc',1 from dual union select 'dw',2 from dual union select 'df',3 from dual;

3 rows inserted

SQL> insert into b
2  select 'dc',1 from dual union select 'dz',6 from dual union select 'ds',7 from dual;

3 rows inserted

SQL> select * from a;

NAME                                                NO
------------------------ ---------------------------------------
dc                                                1
df                                                3
dw                                                2

SQL> select * from b;

NAME                                                NO
------------------------ ---------------------------------------
dc                                                1
ds                                                7
dz                                                6

SQL> select * from b where not exists(select 1 from a where a.name=b.name);

NAME                                                NO
------------------------ ---------------------------------------
ds                                                7
dz                                                6

SQL>


------解决方案--------------------
6楼的就可以了,还可以用外连接实现。

select b.* from b left outer join a
on b.name = a.name
where a.name is null;
------解决方案--------------------
是的.已经想到了 
selec * from b
where b.b_name in 
( select B_NAME from B minus select A_NAME from A )