表A:
a_id,a_title,a_type,a_date
1   , addfaa,  办公室,2006-06-06
3   , dfa,    信息部,2006-06-07
4   , dzdffd,  办公室,2006-06-08
表B:
b_id,b_name,   a_url,          b_update
1   , ert,   ad/fasdfasdf.htm, 2006-06-06
3   , adfa,  ed/adfasd.htm,    2006-06-07
4   , afas,  gg/adf.htm,       2006-06-08
两表结构类似,但列名不一样。我想以两个表的a_date和b_update这个列的时间排序。
我想要结果如下:id,  tn,        a_type,       a_url                     date1   , addfaa,  办公室,      [null]                     2006-06-06
1   , ert,      [null]      ad/fasdfasdf.htm,          2006-06-06
3   , adfa,      [null]     ed/adfasd.htm,             2006-06-07
3   , dfa,     信息部,       [null]                    2006-06-07
4   , dzdffd,  办公室,      [null]                     2006-06-08
4   , afas,    [null]       gg/adf.htm,                 2006-06-08
求SQL语句

解决方案 »

  1.   

    select a_id,a_title,a_type,null,a_date
    from a
    union
    select b_id,b_name,null,a_url,b_update
    from b
    order by a_date
      

  2.   

    select a_id as id,a_title as tn,a_type,NULL as a_url,a_date
    from 表a
    union all
    select b_id as id,b_name as tn,NULL as a_type,a_url ,b_update
    from 表B
    order by a_date
      

  3.   

    create view v as
    (select a_id as id,a_title as tn , a_type ,null as a_url,a_date as date from 表A)
    union all
    (select b_id as id, b_name as tn,null as a_type,a_url,b_update as date from 表B)如果你要合成一个表.
    新建一个表.
    insert into 新表 select * from v
      

  4.   

    select * from (
    select a_id as id,a_title as tn,a_type,null as a_url,a_date as [date]
    from a
    union all
    select b_id as id,b_name as tn,null as a_type,a_url,b_update as [date]
    from b
    ) as t
    order by [date]
      

  5.   

    Select a_id as [id],a_title as tn, a_type,null as a_url,a_date as [date]
    From 表a
    Union 
    Select b_id,b_name,null,a_url,b_update
    From 表b
    Order by [date]