Home » SQL & PL/SQL » SQL & PL/SQL » Select max 3 sal
Select max 3 sal [message #20963] Wed, 03 July 2002 03:54 Go to next message
Sanjay
Messages: 236
Registered: July 2000
Senior Member
please give me the sql by which i can select the highest 3 salaried persor from emp table in Oracle 7.
also give in 8 and 8i version also.
Re: Select max 3 sal [message #20972 is a reply to message #20963] Wed, 03 July 2002 22:45 Go to previous messageGo to next message
Satish Shrikhande
Messages: 167
Registered: October 2001
Senior Member
This is rough idea , better you tune this SQL

select ename,sal from
emp where
sal in(
Select sal
From (select abs (-a.sal) sal
From EMP a
Group by -sal)
Where rownum<3)
order by 2 desc
Re: Select max 3 sal [message #20987 is a reply to message #20972] Thu, 04 July 2002 20:30 Go to previous messageGo to next message
Ravi
Messages: 251
Registered: June 1998
Senior Member
This is an easy one :
select ename,sal from (select ename,sal from emp order by sal desc) where rownum<4;
Re: Select max 3 sal [message #20994 is a reply to message #20963] Fri, 05 July 2002 03:07 Go to previous message
Paramaguru
Messages: 4
Registered: June 2001
Junior Member
Hi,
Pls try the following query..

SELECT a.sal
FROM emp a
WHERE 3=
(SELECT count(distinct(sal))
FROM emp b
WHERE a.sal <= b.sal)

if u want 4th maximum Replace 3 by 4

regards
Paramaguru.N
Previous Topic: help in simple plsql
Next Topic: Re: ORA-12560: TNS:protocol adapter error
Goto Forum:
  


Current Time: Tue Apr 23 12:30:43 CDT 2024