Write query to find the employees with top 5 salaries ?

  
Showing Answers 1 - 27 of 27 Answers

Ritu

  • Mar 18th, 2005
 

select empno,sal from emp X where ( select count(*) from emp where sal > X.sal ) < 5order by sal desc;

  Was this answer useful?  Yes

Amit

  • May 30th, 2005
 

select ename, sal from emp X where (select count (*) from emp where sal > X.sal) < 5 order by sal desc ;

  Was this answer useful?  Yes

Nagaraja Rao S.K

  • Jun 6th, 2005
 

select ename,sal from emp where rownum<=5 
order by sal desc

  Was this answer useful?  Yes

varsha

  • Jun 13th, 2005
 

select distinct sal from emp where sal >=(select distinct a.sal from emp a where (&n-1)=(select count(unique sal) from emp b where b.sal > a.sal)) order by sal desc

  Was this answer useful?  Yes

santhosh

  • Dec 13th, 2005
 

select top 5 EmpName,Salary from Emp_Table
order by Salary desc

  Was this answer useful?  Yes

AMIT Jain

  • May 3rd, 2006
 

select top 5 k.emp_id,k.salary from   (select top 8 * from  emp 
order by salary desc) k order by k.salary desc

  Was this answer useful?  Yes

madug

  • Jan 30th, 2007
 

select empno,sal,rownum from ( select empno,sal from emp order by sal desc) where rownum <=5

  Was this answer useful?  Yes

mkgreets

  • Dec 26th, 2007
 

This is the solution if you want the sql to run in SQL Server 2005 :
--------------------------------------------------------------

select * from employee

where sal in(select distinct top 5 sal from employee order by sal desc)

order by sal desc

---------------------------------------------------------------

Hope it will work for you .
Happy Programming..........

hanimip

  • Jan 31st, 2011
 

SELECT ename, sal FROM (SELECT ename, sal, rank() over (ORDER BY sal DESC) sal_rank FROM emp WHERE sal_rank<=5;




I hope ths work

  Was this answer useful?  Yes

Soubhagya Nayak

  • Dec 6th, 2015
 

This is one of the way to find out top 5 salary and top 5 salary employee using LEVEL Pseudo Column..
Display the top 5 salary values only

SELECT LEVEL,MAX(Sal)
FROM Emp
WHERE LEVEL <=5
CONNECT BY PRIOR Sal>Sal
GROUP BY LEVEL
Display the 5 salary employees details
SELECT *
FROM Emp
WHERE Sal in
(
SELECT MAX(Sal)
FROM Emp
WHERE LEVEL < 6
CONNECT BY PRIOR Sal>Sal
GROUP BY LEVEL
)

// This is also possible using ROWNUM Pseudo Column..

  Was this answer useful?  Yes

PRANJAL

  • Nov 5th, 2019
 

SELECT * FROM EMP WHERE ROWNUM < = 3 ORDER BY SAL DESC;

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions