查询数据库-数据库语句

来源:百度知道 编辑:UC知道 时间:2024/06/17 01:36:51
有两个表,都是存储了表项有标题title和时间time两个内容,怎么样将这两个表中标题title按时间排序取出来(升序或降序都可以)。例如:表一中,title:demo1,time:2008-12-12;title:demo2,time:2008-12-10;表二中,title:example,time:2008-12-11.
结果为:
title time
demo2 2008-12-10
example 2008-12-11
demo1 2008-12-12
求它的sql语句!急,结果正确将不计悬赏分

select * from (select title,time from 表1
union all
select title,time from 表2) as 表3
order by time

记住一定要用 union all ,否则会少数据。

select title,time from 表1
union all
select title,time from 表2
order by time

这就行了吧
那么麻烦嘎哈呀

可能还需要调试一下你先试试
select a.title,b.title,(case when b.time is null then a.time else b.time end) as time
from a full join b on a.title=b.title
order by time

select title,time from A
union
select title,time from B
order by time

create table c (title varchar,tim datetime)
insert into c select * from a
insert into c select * from b
select * from c order by tim des