Re: Returning top 4 records from a query

From: GHouck <hksys_at_teleport.com>
Date: Wed, 02 Feb 2000 03:12:48 -0800
Message-ID: <38981130.2233_at_teleport.com>


Nicky Taylor wrote:
>
> How do I just return the top 4 records from a query result?
>
> Thanks in advance
> Nicky Taylor

Since you did not specify that they be in any particular order, you might try:

select *
from mytable
where ... and rownum<5;

The way I understand it, if you want them in order, the 'rownum' doesn't really give you the 'sorted' top # of rows, so an 'order by' is a waste of time. However, if the values you are sorting on are unique, this might work:

select *
from (select mycol from mytable group by mycol) where rownum<5;

(assuming the 'group by' returns the rows ordered by 'mycol')

Yours,

Geoff Houck
systems hk
hksys_at_teleport.com
http://www.teleport.com/~hksys Received on Wed Feb 02 2000 - 12:12:48 CET

Original text of this message