select * from(
select * from supply
union all
select * from demand
)a order by CreateDate

解决方案 »

  1.   

    --测试--测试数据
    create table supply(Id int,Title varchar(10),Content varchar(10),CreateDate datetime,Sort varchar(10))
    insert into supply
    select 1,'t01','c01','2003-1-3','supply'
    union all select 2,'t02','c02','2003-1-8','supply'create table demand(Id int,Title varchar(10),Content varchar(10),CreateDate datetime,Sort varchar(10))
    insert into demand
    select 1,'dt01','dc01','2003-1-4','demand'
    union all select 2,'dt02','dc02','2003-1-5','demand'
    go--查询
    select * from(
    select * from supply
    union all
    select * from demand
    )a order by CreateDate
    go--删除测试环境
    drop table supply,demand/*--测试结果
    Id          Title      Content    CreateDate                Sort    
    ----------- ---------- ---------- ------------------------- --------
    1           t01        c01        2003-01-03 00:00:00.000   supply
    1           dt01       dc01       2003-01-04 00:00:00.000   demand
    2           dt02       dc02       2003-01-05 00:00:00.000   demand
    2           t02        c02        2003-01-08 00:00:00.000   supply(所影响的行数为 4 行)
    --*/
      

  2.   

    select * from(
    select * from supply
    union all
    select * from demand
    )a order by CreateDate