我想更新下一个表A现在有另一个表B,现在想把在B中的不在A中的查出来,例如如下。
表A           表B
 ID    name    ID   name
 1.0   cha0    2.0  cha1
 2.0   cha1    3.0  cha2
 3.0   cha2    4.0  cha3查询后 
 ID   name
 3.0  cha3
用了
select   *   from   b   where   b.name   not   in   (select   name   from  a  )查不出来呀 求救中

解决方案 »

  1.   

    你这样是不对滴,后面改掉,select name from a where a.name = b.name,这个结果是两个表都有的,当然你要跟你前面那一部分放一起查,然后再查b.name不在这个结果集里面的。
      

  2.   


    --這樣就可以查出來了
    select * from B where not exists (select 1 from A where A.name=B.name);
      

  3.   

    你看下你的表A和B是否都有記錄,可能是你把數據插錯表了SQL> create table A(
      2  ID varchar2(3),
      3  name varchar2(5)
      4  );已建立表格.SQL> create table B(
      2  ID varchar2(3),
      3  name varchar2(5)
      4  );已建立表格.SQL> insert into A values('1.0','cha0');已建立 1 個資料列.SQL> insert into A values('2.0','cha1');已建立 1 個資料列.SQL> insert into A values('3.0','cha2');已建立 1 個資料列.SQL> insert into B values('2.0','cha1');已建立 1 個資料列.SQL> insert into B values('3.0','cha2');已建立 1 個資料列.SQL> insert into B values('4.0','cha3');已建立 1 個資料列.SQL> commit;確認完成.SQL> select * from b where b.name not in (select name from a )
      2  ;ID  NAME                                                                        
    --- -----                                                                       
    4.0 cha3     
      

  4.   

    CREATE TABLE ta1(ID NUMBER, NAME VARCHAR2(10));
    CREATE TABLE ta2(ID number,NAME VARCHAR2(10));INSERT INTO ta1 VALUES(1,'cha0');
    INSERT INTO ta1 VALUES(2,'cha1');
    INSERT INTO ta1 VALUES(3,'cha2');INSERT INTO ta2 VALUES(2,'cha1');
    INSERT INTO ta2 VALUES(3,'cha2');
    INSERT INTO ta2 VALUES(4,'cha3');COMMIT;select * from ta2 b where b.name not in (select name FROM ta1 a )--4.0 cha3楼主你是正确的。
      

  5.   

    答案解决尽量结贴哦!
    http://topic.csdn.net/u/20100308/09/460d2b6e-4f38-4829-b82c-b818b729fa6d.html?78595