两个表连接查询
来源:百度知道 编辑:UC知道 时间:2024/06/08 17:32:14
比如我有两个表 table1 , table2
两个表中都有 title,inser_date 字段。 (题目,添加时间)
如果我要同时查询 两个表中的 最新添加的10条数据
该怎么查呢?
我用的是oracle. 在线等~!
两个表中都有 title,inser_date 字段。 (题目,添加时间)
如果我要同时查询 两个表中的 最新添加的10条数据
该怎么查呢?
我用的是oracle. 在线等~!
select title,inser_date
(select title,inser_date,rownum as rn
from
(select * from table1
union
select * from table2)
order by inser_date desc
)
where rn < 11
你的问题不是很清楚。最新添加的数据,是以哪个表为准呢。
如果是单表的话可以这么查
select * from(
select * from table1
order by inser_date1 )
where rownum<=10
;
但是你题目上是说表连接的,我有些不明白。
select top(10) title from t1,t2 order by insert_date desc;
select top10 title,inser_date from table1 order by inser_date desc