Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: SQL Query

Re: SQL Query

From: DI Karl Heinz Hörmann <kh.hoermann_at_penta.at>
Date: Fri, 28 Jan 2000 00:33:28 +0100
Message-ID: <86qkak$9m7$1@newsmaster01.magnet.at>

Kinna Patel wrote in <389022f6.2081212_at_news.demon.co.uk>...
>How can I write an SQL query which will return the first record in a
>recordset.

You can use the ROWNUM Pseudocolumn -

For each row returned by a query, the ROWNUM pseudocolumn returns a number indicating the order in which Oracle selects the row from a table or set of joined rows. The first row selected has a ROWNUM of 1, the second has 2, and so on.

You can use ROWNUM to limit the number of rows returned by a query, as in this example:

SELECT *
    FROM emp
    WHERE ROWNUM < 10;

But be aware of this fact:
Oracle assigns a ROWNUM value to each row as it is retrieved, before rows are sorted for an ORDER BY clause, so an ORDER BY clause normally does not affect the ROWNUM of each row. However, if an ORDER BY clause causes Oracle to use an index to access the data, Oracle may retrieve the rows in a different order than without the index, so the ROWNUMs may be different than they would be without the ORDER BY clause.

Hth Received on Thu Jan 27 2000 - 17:33:28 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US