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: Top 10 rows from a sorted resultset

Re: Top 10 rows from a sorted resultset

From: Daniel Morgan <dmorgan_at_exesolutions.com>
Date: Thu, 22 Aug 2002 16:03:28 GMT
Message-ID: <3D650B40.1DEB10D3@exesolutions.com>


BVince2172 wrote:

> Using Oracle 8i, how would I return the first n rows in a query after an order
> by? In Transact-SQL there's TOP, but as far as I am aware this isn't available
> in Oracle.
>
> It's simple enough to do without the order by:
>
> SELECT Name, DOB
> FROM tMyTable
> WHERE rownum <11
>
> ...to return the first 10 rows, but with an order by the results are ordered
> AFTER cutting the first 10 rows.

Use an in-line view ... known in TSQL as a derived table.

SELECT *
FROM (

             your select statement here with the order by clause
             )

WHERE rownum < 11;

Daniel Morgan Received on Thu Aug 22 2002 - 11:03:28 CDT

Original text of this message

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