Re: Bring Back Only One Record From A Query
Date: Wed, 24 Nov 1999 01:37:09 GMT
Message-ID: <81ffg5$s5q$1_at_nnrp1.deja.com>
Anton,
Before you dismiss the possibility of using ROWNUM, consider the
following:
SQL> select empno, rownum from emp;
EMPNO ROWNUM
---------- ----------
7369 1 7499 2 7521 3 7566 4 7654 5 7698 6 7782 7 7788 8 7839 9 7844 10 7876 11 7900 12 7902 13 7934 14
14 rows selected.
SQL> select empno, rownum from emp order by empno desc;
EMPNO ROWNUM
---------- ----------
7934 1 7902 2 7900 3 7876 4 7844 5 7839 6 7788 7 7782 8 7698 9 7654 10 7566 11 7521 12 7499 13 7369 14
14 rows selected.
SQL> select empno from emp where rownum = 1 order by empno;
EMPNO
7369
SQL> select empno from emp where rownum = 1 order by empno desc;
EMPNO
7934
Notice that the sort order changes the ROWNUM associated with a given record, unlike ROWID which is fixed for a given row. Hope this helps.
In article <81f0j8$ha1$1_at_nnrp1.deja.com>,
aochss_at_my-deja.com wrote:
> Howdy,
>
> I am trying to figure out a way of bringing back only the first record
> of a query without having to use a cursor.
>
> I can't use the Rownum keyword because the sort by is the most
> important part of the query.
>
> Does anyone have any ideas?
>
> Thanks,
>
> Anton
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
>
Sent via Deja.com http://www.deja.com/
Before you buy.
Received on Wed Nov 24 1999 - 02:37:09 CET