你这样查不到你想要的结果.
那样会导致查询到很多很多的记录!
建议改成
select * from a
where a.name not in (select b.name from b
where b.name is not null)

解决方案 »

  1.   

    select * from a where not exists (select * from b where a.name=b.name)
    也能用
      

  2.   

    不好意思,是我搞错了,没有 distinct!
    我的SQL:  select distinct name from a where name not in(select distinct name from b);
    谢谢两位的帮助了!
      

  3.   

    SQL> select * from a;      COL1
    ----------
             1
             2
             3
             4
             5
             6
             7
             8
             9
            1010 rows selected.SQL> select * from b;      COL1
    ----------
             1
             2
             3
             4
             5SQL> select * from a where not exists (select * from b where a.col1=b.col1);      COL1
    ----------
             6
             7
             8
             9
            10不是要上面的结果???
      

  4.   

    zzwind5() 兄:
    连接的结果有三种情况:a表存在,b表不存在;a表存在,b表存在;a表不存在,b表存在。你的语句多了一种a表没有,b表有的情况。
      

  5.   

    楼上的看来你没有真正理解 exists 和 not exists 的用法
    select * from a where not exists (select * from b where a.col1=b.col1);
    等同于
    select * from a where a.col1 not in (select b.col1 from b );