有3个表,a,b,c
select * from a where a.n in(select n from b )
只有当 B表中没有数据时才查询c表(select n from c)以C表作为条件,Sql应该怎么写?
select * from a where a.n in(select n from b )
只有当 B表中没有数据时才查询c表(select n from c)以C表作为条件,Sql应该怎么写?
where 1>=(select count(1) from b)
and 其他条件;
union
select * from a where a.n in (select n from c)
where b表的其他条件 -- 有条件就加,没有拉倒
union all
select * from c
where 1>=(select count(1) from b)
and c表的其他条件;