table1
column1  column2  
1          a
2          b
3          c
table2
column1
1
2
当table2有数据时(像上面那个数据),则查出table的前2行,
当table2没有数据时,则查出table1的全部数据。OracleSQL

解决方案 »

  1.   


    select * from table1
    where (select count(1) from table2)=0 or column1 in(select * from table2)
      

  2.   

    如果table2为1 3 那返回什么值?LZ描述的不够清楚
      

  3.   

    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)