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: How to limit the number of rows returned in a select statement

Re: How to limit the number of rows returned in a select statement

From: Paul Sandwell <paul_sandwell_at_sdt.com>
Date: 1997/06/04
Message-ID: <33959A51.5FE9@sdt.com>#1/1

Stefan Fallet wrote:
>
> Hi does anyone know how to limit he number of rows returned by a select.
>
> I tryed using rownum. but this does not work with an order by.
>
> my select: select X,Y from table_a order by Y.
>
> I only want the first 15 rows after the sort.
> Using rownum <=15 brings back the first 15 rows in the table.
>
> Need help fast
>
> Thanks
>
> Stefan Fallet
>
> E-Mail: stfallet_at_fallet.com

Depending on the reason you want to limit the number of rows returned, you can fudge it.

If you want to see only a few rows because that gives whatever info you need and the query execution itself is not a matter of concern, then use your original SELECT statement as a subselect of an outer SELECT which limits on ROWNUM. Like this:

SELECT * from (select X,Y from table_a order by Y) where rownum < 10;

If, on the other hand, you want to limit the number of rows because the query execution is a problem, then I'm afraid you're stuck.

Good luck!

Paul Received on Wed Jun 04 1997 - 00:00:00 CDT

Original text of this message

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