表a id title addtime
1 aaa 2007-02-23
2 bbb 2007-06-05表bid title addtime
1 assf 2007-03-23
2 dfsd 2007-05-05现在想把连个表合并显示按时间倒序排列,输出结果为:addtime title2007-06-05 bbb
2007-05-05 dfsd
2007-03-23 assf
2007-02-23 aaa
1 aaa 2007-02-23
2 bbb 2007-06-05表bid title addtime
1 assf 2007-03-23
2 dfsd 2007-05-05现在想把连个表合并显示按时间倒序排列,输出结果为:addtime title2007-06-05 bbb
2007-05-05 dfsd
2007-03-23 assf
2007-02-23 aaa
select addtime,title from a
union all
select addtime,title from b ) as c
order by addtime desc
union all
select addtime,title from b order by addtime desc
order by addtime desc
union all
select addtime , title from a
order by a.addtime desc
insert into a values(1, 'aaa', '2007-02-23')
insert into a values(2, 'bbb', '2007-06-05')
create table b(id int,title varchar(10),addtime datetime)
insert into a values(1, 'assf', '2007-03-23')
insert into a values(2, 'dfsd', '2007-05-05')
goselect addtime , title from a
union all
select addtime , title from b
order by a.addtime descdrop table a,b
/*
addtime title
------------------------------------------------------ ----------
2007-06-05 00:00:00.000 bbb
2007-05-05 00:00:00.000 dfsd
2007-03-23 00:00:00.000 assf
2007-02-23 00:00:00.000 aaa(所影响的行数为 4 行)
*/
insert into a values(1, 'aaa', '2007-02-23')
insert into a values(2, 'bbb', '2007-06-05')
create table b(id int,title varchar(10),addtime datetime)
insert into a values(1, 'assf', '2007-03-23')
insert into a values(2, 'dfsd', '2007-05-05')
goselect convert(varchar(10),addtime,120) addtime , title from a
union all
select convert(varchar(10),addtime,120) addtime , title from b
order by a.addtime descdrop table a,b
/*
addtime title
---------- ----------
2007-06-05 bbb
2007-05-05 dfsd
2007-03-23 assf
2007-02-23 aaa(所影响的行数为 4 行)
*/
union all
select addtime,title from b order by addtime desc
union all
select addtime,title from b order by addtime desc