hi, can anyone plz tell me how to find the only first 3 highest salary from emp table in oracle.
I have used order by desc but it shows all the sal of all employees
regards
Sukhbir
-
first 3 highest salary from emp table in oracle. (4 messages)
- Posted by: sukhbir bhavra
- Posted on: March 24 2003 12:21 EST
Threaded Messages (4)
- first 3 highest salary from emp table in oracle. by Viral Vyas on March 24 2003 12:41 EST
- first 3 highest salary from emp table in oracle. by David Hanna on March 24 2003 17:34 EST
- Reply by Alex Pisarev on March 25 2003 02:43 EST
- first 3 highest salary from emp table in oracle. by Ranjith Kumar on December 14 2010 23:22 EST
-
first 3 highest salary from emp table in oracle.[ Go to top ]
- Posted by: Viral Vyas
- Posted on: March 24 2003 12:41 EST
- in response to sukhbir bhavra
You could use the rownum variable to list the top three
Select xxxx
from yyy
where
zzz = ??? and
rownum -
first 3 highest salary from emp table in oracle.[ Go to top ]
- Posted by: David Hanna
- Posted on: March 24 2003 17:34 EST
- in response to sukhbir bhavra
select top 3 sal from employee order by sal -
Reply[ Go to top ]
- Posted by: Alex Pisarev
- Posted on: March 25 2003 02:43 EST
- in response to sukhbir bhavra
Sukhbir,
You should use rownum, however, remember, that rownum doesn't work with order properly, so you should use subquery:
select * from (select * from emp order by sal) where rownum<3
That should work.
Alex -
first 3 highest salary from emp table in oracle.[ Go to top ]
- Posted by: Ranjith Kumar
- Posted on: December 14 2010 23:22 EST
- in response to sukhbir bhavra
select * from (select distinct salary from ran1 order by salary desc)where rownum<=3;
SALARY
----------
20000
14000
12000