Home » SQL & PL/SQL » SQL & PL/SQL » Top five salaries from emp
Top five salaries from emp [message #768] Sun, 03 March 2002 23:05 Go to next message
Daman
Messages: 4
Registered: March 2002
Junior Member
I want to display top five salaries from emp table without using max and count as well as subqueries.
i want to use rownum.
Re: Top five salaries from emp [message #776 is a reply to message #768] Mon, 04 March 2002 02:12 Go to previous messageGo to next message
pratap kumar tripathy
Messages: 660
Registered: January 2002
Senior Member
u do not want to use max,count or subqueries, why ?. u can not use rownum to find the top 5 salary without using subquery
Re: Top five salaries from emp [message #827 is a reply to message #768] Wed, 06 March 2002 10:34 Go to previous messageGo to next message
sfhollands
Messages: 15
Registered: October 2001
Junior Member
a relatedquery atleast has tobe used

select sal from (select sal from emp order by sal desc)
where rownum<6
Re: Top five salaries from emp [message #829 is a reply to message #768] Wed, 06 March 2002 13:21 Go to previous message
Mike
Messages: 417
Registered: September 1998
Senior Member
The fastest way to do this with Oracle 8.1.6 (or later) is:

select ename, sal from
( select ename, sal,
dense_rank() over(order by sal asc) as sal_rank
from scott.emp
)
where sal_rank < 6
Previous Topic: system requirements
Next Topic: View and order by
Goto Forum:
  


Current Time: Sat Apr 20 02:48:24 CDT 2024