日期:2014-05-19  浏览次数:20547 次

关于not in的问题
select   *   from   A.a   where     a.custid   not   in   (select   b.custid   from   B.b)
如果B表中有记录,则查询正确;如果B表内无记录,则查询结果为空(正确结果应该为A表中的所有记录)

这个问题不知如何解决。
谢谢


------解决方案--------------------
---try

select * from A a where not exists (select 1 from B.b where b.custid=a.custid)
------解决方案--------------------
if exists(select * from A.a where a.custid not in (select b.custid from B.b)
)
select * from A.a where a.custid not in (select b.custid from B.b)
else

select * from A.a where
------解决方案--------------------
if exists(select b.custid from B.b)
select * from A.a where a.custid not in (select b.custid from B.b)
else
select * from A.a

------解决方案--------------------
我就说应该不会这样地
------解决方案--------------------
if exists(select * from A.a where a.custid not in (select b.custid from B.b))
select * from A.a where a.custid not in (select b.custid from B.b))
else
select ' '