Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.server -> Re: Limiting returned data from SQL Select Satement
Sorry about the misinformation!! ORDER BY does not work. However, using a GROUP BY clause with an in-line view does. So a query such as
select * from
(select empno, ename, sal
from scott.emp
group by sal, empno, ename)
where rownum <= 5;
will give you the top five employee numbers and names based on salary.
I had always used a group by with a max or sum of a value in the past. I never tried the order by clause and posted the message without testing it. I hope this revised suggestion helps.
-DKP.
Jurij Modic wrote in message <34ef3c6d.2260827_at_www.sigov.si>...
>On Thu, 19 Feb 1998 16:02:48 -0700, "Darryl Petruska"
><dkpetrus_at_data-insight.com> wrote:
>
>>If you want the top ten values from a list ordered by field 'X' then
perform
>>the following query:
>>
>>select *
>>from (select * from table_name order by x)
>>where ROWNUM <= 10
>
>This wont work! You can't use ORDER BY in a view - and you are using
>in-line view in your FROM clause.
>
>Regards,
>============================================================
>Jurij Modic Republic of Slovenia
>jurij.modic_at_mf.sigov.mail.si Ministry of Finance
>============================================================
>The above opinions are mine and do not represent any official
>standpoints of my employer
Received on Mon Feb 23 1998 - 00:00:00 CST
![]() |
![]() |