表A
col001 col002 col003
00123   aa     1.0
00122   bb     2.00
00111   cc     3.00
表B
col001 col002 col003
00123   aa     1.0
00122   bb     2.00
01123   aa     1.0
02122   bb     2.00
03123   aa     1.0
04122   bb     2.00现在我想表A的数据中的col001字段不在表B中取出来
select * from A where col001 not in (select col001 from B)这样一条也没取到?
这是为什么啊?

解决方案 »

  1.   

    select * from A where ltrim(rtrim(col001)) not in (select ltrim(rtrim(col001)) from B)
      

  2.   

    SELECT * FROM 表A a,表B b
    where a.col001=b.col001看看这个能出来记录吗?
      

  3.   

    因为存在
    select col001 from B where col001 is null
      

  4.   

    有人专门问过:
    http://topic.csdn.net/u/20110129/13/634be4df-ad97-405f-ae6f-3f04ea0b0f8c.html
      

  5.   


    --1
    select *
    from a
    where co1001 not in (select isnull(co1001,'') from b)--2
    select *
    from A
    where not exists(select 1 from B where col001=A.col001)
      

  6.   

    not in的无相关子查询 注意null的问题你后面的子查询存在空值 所以没记录
      

  7.   

     把not in 改为not exists
      

  8.   

    有一种可能
    B表里面有为Null的值
    select * from A where col001 not in (select col001 from B where col001 is not null )
      

  9.   

    select * from A where col001 not in (select col001 from B where col001 is not null)
    即可