select case
when 条件1
then (select xm,id,zjh from 表1 )
else (select xm,id,zjh from 表1 union select xm,id,zjh from 表2 )
end
when 条件1
then (select xm,id,zjh from 表1 )
else (select xm,id,zjh from 表1 union select xm,id,zjh from 表2 )
end
if 条件1
select xm,id,zjh from 表1
else
select xm,id,zjh from 表1
union
select xm,id,zjh from 表2
when 条件1
then (select xm,id,zjh from 表1 )
else (select xm,id,zjh from 表1 union select xm,id,zjh from 表2 )
end
-------------------這樣寫是不行的,case when 隻能返回單一值if exists(select 1 from t where ...)select xm,id,zjh from 表1
else
select xm,id,zjh from 表1 union select xm,id,zjh from 表2
select xm,id,zjh from 表1
else
select xm,id,zjh from 表1
union
select xm,id,zjh from 表2
select xm,id,zjh from 表1
else
select xm,id,zjh from 表1
union
select xm,id,zjh from 表2
else
select xm,id,zjh from 表1 union select xm,id,zjh from 表2这种方法是最好的,个人认为!