Prepare for your Next Interview
This is a discussion on 2nd high sal within the Data Warehousing forums, part of the Databases category; how can i retrieve the 2nd highest salary from emp table (oracle)...
|
|||
|
Re: 2nd high sal
To get the dynamic salary(for example 2nd sal, 3rd sal like that) ---------------------------------------------------------------- select * from emp a where &n=(select * from emp b where a.sal < b.sal) or select max(sal) from emp where sal>(select max(sal) from emp)
Last edited by cme_prak : 3 Weeks Ago at 05:17 AM. Reason: Format Purpose |
|
|||
|
Re: 2nd high sal
Here are two queries to get the Nth highest salary:
1. This query gives you all the columns of emp table SELECT * FROM (SELECT f.*,dense_rank() OVER(ORDER BY SALARY DESC) rn FROM Emp f) WHERE rn=&n 2. This query gives you the salary column data only SELECT MIN(SALARY) FROM EMP f WHERE &n > (SELECT COUNT(DISTINCT SALARY) FROM emp where salary > f.salary) |
|
|||
|
Re: 2nd high sal
The Advantage of using a dense_rank is that in case if there are more than 1 employee having a same salary at Nth position then both the employee details will be listed
|
|
|||
|
Re: 2nd high sal
Quote:
this is not working in oracle. can u please tell us how to handle it in oracle(2nd high sal) |
![]() |
|
| Thread Tools | |
| Display Modes | |
|
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Foundations of High Buildings | joel | Civil Engineering | 7 | 4 Weeks Ago 09:54 AM |
| What are high values in cobol???? | prasenjit_in | MainFrame | 0 | 05-12-2008 03:47 AM |
| Create your own high-quality podcasts. | JobHelper | Geeks Lounge | 0 | 03-18-2008 06:00 AM |
| High End civil engg softwares | praveerkumar | Civil Engineering | 1 | 07-18-2007 03:28 PM |
| What is the difference between High and critical. | Rani99 | Testing Issues | 4 | 05-08-2007 02:10 AM |