假设有两张表A,B
两张表结构完全一样,都各有一个字段 time
A内有3条记录 2010-06-02 11:11:11,2010-06-05 11:11:11,2010-06-09 11:11:11
B内有2条记录 2010-06-02 13:31:31,2010-06-10 11:11:11现在我想查出的结果是从这两张表查出所有不重复的四个日期,2010-06-02,2010-06-05 ,2010-06-09,2010-06-10求助!
两张表结构完全一样,都各有一个字段 time
A内有3条记录 2010-06-02 11:11:11,2010-06-05 11:11:11,2010-06-09 11:11:11
B内有2条记录 2010-06-02 13:31:31,2010-06-10 11:11:11现在我想查出的结果是从这两张表查出所有不重复的四个日期,2010-06-02,2010-06-05 ,2010-06-09,2010-06-10求助!
select to_char(time,'yyyy-mm-dd') from a
union
select to_char(time,'yyyy-mm-dd') from b
select to_date('2010-06-02 11:11:11','yyyy-mm-dd hh24:mi:ss') time from dual
union all
select to_date('2010-06-05 11:11:11','yyyy-mm-dd hh24:mi:ss') time from dual
union all
select to_date('2010-06-09 11:11:11','yyyy-mm-dd hh24:mi:ss') time from dual
)
,B as(
select to_date('2010-06-02 13:31:31','yyyy-mm-dd hh24:mi:ss') time from dual
union all
select to_date('2010-06-10 11:11:11','yyyy-mm-dd hh24:mi:ss') time from dual
)
select to_char(A.time,'yyyy-mm-dd') from A
union
select to_char(time,'yyyy-mm-dd') from B
select to_char(A.time,'yyyy-mm-dd') time from A
union
select to_char(time,'yyyy-mm-dd') time from B
) order by time