我写了2个sql
select t1.tel from test1 t1 where t1.tel not in (select t2.tel from test2 t2  where t2.tel=t1.tel)

select t1.tel from test1 t1 where t1.tel not in (select t2.tel from test2 t2)
得到的结果却不一样 
第一个能得到结果 第二个sql却什么都得不到谁能给解释下??? 另外如果表里只有几行数据的话两个sql结果又一样

解决方案 »

  1.   

    分别看看两个子语句select t2.tel from test2 t2 where t2.tel=t1.tel
    和select t2.tel from test2 t2的结果集是什么呗。第一个子语句的结果集应该比第二个少,第二个语句是test2中所有的数据。也就是说:第二个SQL语句,要找test1中的tel号,在test2中不存在的。
      

  2.   

    第一个不是找test1中的tel号在test2中不存在的么? 只不过是第二个字句获得的结果集大而已 但是第二个就查不到任何结果
      

  3.   

    not in (结果集) 只要结果集里有一个为null 无记录返回。
      

  4.   

    select * from dual where 1 not in (2,3)select * from dual where 1 not in (2,3,null)运行一下就知道了
      

  5.   

    你结果集里面有null,执行not in null,无论在什么情况下执行的结果都是为空的,所以结果才会不一样