多个表 t1,t2,t3..... 其中都有两个字段id,rq我想取每个表的第一条数据 ,按日期排序id
t1id
t2id
t3id
.....不想用下列办法,还有其他办法吗?》
select id from t1 where rownum=1 order by rq union 
select id from t2 where rownum=1 order by rq union 
select id from t3 where rownum=1 order by rq

解决方案 »

  1.   


    --没想到其他方法,不过,最好用union all
    SQL> create table t1 as
      2  select * from scott.emp
      3  order by hiredate desc;Table createdSQL> create table t2 as
      2  select * from scott.emp
      3  order by hiredate;Table createdSQL> select hiredate,job,ename from t1 where rownum=1
      2  union all
      3  select hiredate,job,ename from t2 where rownum=1
      4  /HIREDATE    JOB       ENAME
    ----------- --------- ----------
    1987-5-23   CLERK     ADAMS
    1980-12-17  CLERK     SMITH