Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> Re: How to limit the number of rows returned in a select statement
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
![]() |
![]() |