Krishna Logo
qa training in canada now
Divied
Call: Anusha @ 1 (877) 864-8462

 

Latest News
Home Navigation Divied
DATABASE Navigation Divied SQL Navigation Divied How to find the N th Highest salary from emp table ?
How To Find The N Th Highest Salary From Emp Table ?
How to find the N th Highest salary from emp table ?

SOLUTION1

select * from ( select ename,sal,dense_rank() over (order by sal desc) rank from emp) where rank=2

 

SOLUTION2

select * from ( select ename,sal,deptno,dense_rank() over (partition by deptno order by sal desc) rank from emp) where rank=2

 

SOLUTION3

SELECT * FROM emp a WHERE (&n-1)=(SELECT count(DISTINCT b.sal) FROM emp bWHERE a.sal<b.sal);

 

SOLUTION4

 To find the nth highest salary and find the second largest value in a given column as you asked both are same. So, both of the above scenarios the below is the query:

SELECT * FROM table_name a WHERE &n=(SELECT count(DISTINCT(sal)) FROMTable_name b WHERE a.sal<b.sal);


Shadow Bottom
 
 
© 2005 -