table1
column1 column2
1 a
2 b
3 c
table2
column1
1
2
当table2有数据时(像上面那个数据),则查出table的前2行,
当table2没有数据时,则查出table1的全部数据。
Oracle SQL
------解决方案--------------------
select * from table1
where (select count(1) from table2)=0 or column1 in(select * from table2)
------解决方案--------------------
select col1,col2 from tab1 where not exists (select * from tab2)
union all
select col1,col2 from tab1 where col1 in (select col1 from tab2)