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
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
这两个union连接的select语句的查询结果不同,但是我想把这两个union的语句连接到一起不知道用什么关键字,能够查询出满足任其中的一个union条件,希望各位高手帮帮忙!
7 个解决方案
#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
呵呵,不是两个表,是四个表,你在看下,我已经两两连接了,现在是想把已经连接好的语句再连接
#3
在加个union all 不就可以了吗?
#4
你的意思是这样吗
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 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
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 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
#5
恩,如果你想把语句写的更好看可以用括号括起来
(...)
union all
(...)
(...)
union all
(...)
#6
呵呵,谢谢啦,我一直以为union all和union都是查询相同字段的呢
#7
(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)
#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
呵呵,不是两个表,是四个表,你在看下,我已经两两连接了,现在是想把已经连接好的语句再连接
#3
在加个union all 不就可以了吗?
#4
你的意思是这样吗
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 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
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 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
#5
恩,如果你想把语句写的更好看可以用括号括起来
(...)
union all
(...)
(...)
union all
(...)
#6
呵呵,谢谢啦,我一直以为union all和union都是查询相同字段的呢
#7
(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)