select cut_start_date,cut_end_date from table_A  
where (select sysdate from dual)>=cut_start_date and (select sysdate from dual)<=cut_end_date
union 
select cut_start_date,cut_end_date from table_B 
where (select sysdate from dual)>=cut_start_date and (select sysdate from dual)<=cut_end_dateselect up_start_date,up_end_date from table_C 
where (select sysdate from dual)>=up_start_date and (select sysdate from dual)<=up_end_date
union
select up_start_date,up_end_date from table_D  
where (select sysdate from dual)>=up_start_date and (select sysdate from dual)<=up_end_date这两个union连接的select语句的查询结果不同,但是我想把这两个union的语句连接到一起不知道用什么关键字,能够查询出满足任其中的一个union条件,希望各位高手帮帮忙!

解决方案 »

  1.   

    --你这两个表有什么联系吗?如果没联系的话还是用union吧
    --可以稍微修改下
    select cut_start_date,cut_end_date from table_A   
    where cut_start_date<=sysdate and cut_end_date>=sysdate
    union  
    select cut_start_date,cut_end_date from table_B  
    where cut_start_date<=sysdate and cut_end_date>=sysdate
      

  2.   

    在加个union all 不就可以了吗? 
      

  3.   

    你的意思是这样吗
    select cut_start_date,cut_end_date from table_A   
    where (select sysdate from dual)>=cut_start_date and (select sysdate from dual)<=cut_end_date
    union  
    select cut_start_date,cut_end_date from table_B  
    where (select sysdate from dual)>=cut_start_date and (select sysdate from dual)<=cut_end_dateunion allselect up_start_date,up_end_date from table_C  
    where (select sysdate from dual)>=up_start_date and (select sysdate from dual)<=up_end_date
    union
    select up_start_date,up_end_date from table_D   
    where (select sysdate from dual)>=up_start_date and (select sysdate from dual)<=up_end_date
      

  4.   

    恩,如果你想把语句写的更好看可以用括号括起来
    (...)
    union all
    (...)
      

  5.   

    呵呵,谢谢啦,我一直以为union all和union都是查询相同字段的呢
      

  6.   


    (select cut_start_date,cut_end_date from table_A   
    where (select sysdate from dual)>=cut_start_date and (select sysdate from dual)<=cut_end_date
    union  
    select cut_start_date,cut_end_date from table_B  
    where (select sysdate from dual)>=cut_start_date and (select sysdate from dual)<=cut_end_date)
    union / union all  --union 排序去重 union all 不排序不去重
    (select up_start_date,up_end_date from table_C  
    where (select sysdate from dual)>=up_start_date and (select sysdate from dual)<=up_end_date
    union
    select up_start_date,up_end_date from table_D   
    where (select sysdate from dual)>=up_start_date and (select sysdate from dual)<=up_end_date)