有3个表,a,b,c 
select * from a where a.n in(select n from b ) 
 只有当 B表中没有数据时才查询c表(select n from c)以C表作为条件,Sql应该怎么写?

解决方案 »

  1.   

    -- 能不能说明白点啊?select n from c
    where 1>=(select count(1) from b)
    and 其他条件;
      

  2.   

    select * from a where a.n in (select n from b)
    union 
    select * from a where a.n in (select n from c) 
      

  3.   

    select * from b
    where b表的其他条件  -- 有条件就加,没有拉倒
    union all
    select * from c
    where 1>=(select count(1) from b)
    and c表的其他条件; 
      

  4.   

    如果在B表中什么也没查到,才去查询c表,这个1>=是不是有些问题啊?