Geeks Talk

Prepare for your Next Interview




2nd high sal

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)...


Go Back   Geeks Talk > Databases > Data Warehousing

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 07-29-2008
Junior Member
 
Join Date: Jul 2008
Location: pune
Posts: 3
Thanks: 0
Thanked 1 Time in 1 Post
anil.curse is on a distinguished road
2nd high sal

how can i retrieve the 2nd highest salary from emp table (oracle)
Reply With Quote
The Following User Says Thank You to anil.curse For This Useful Post:
Sponsored Links
  #2 (permalink)  
Old 3 Weeks Ago
Contributing Member
 
Join Date: Dec 2007
Location: INDIA
Posts: 36
Thanks: 1
Thanked 6 Times in 6 Posts
cme_prak is on a distinguished road
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
Reply With Quote
  #3 (permalink)  
Old 3 Weeks Ago
Contributing Member
 
Join Date: Nov 2008
Location: Chennai
Posts: 74
Thanks: 0
Thanked 7 Times in 7 Posts
amitpatel66 is on a distinguished road
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)
Reply With Quote
  #4 (permalink)  
Old 3 Weeks Ago
Contributing Member
 
Join Date: Nov 2008
Location: Chennai
Posts: 74
Thanks: 0
Thanked 7 Times in 7 Posts
amitpatel66 is on a distinguished road
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
Reply With Quote
  #5 (permalink)  
Old 2 Weeks Ago
Junior Member
 
Join Date: Oct 2008
Location: usa
Posts: 5
Thanks: 1
Thanked 1 Time in 1 Post
developer_veni is on a distinguished road
Re: 2nd high sal

Quote:
Originally Posted by cme_prak View Post
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)
Hi,

this is not working in oracle.
can u please tell us how to handle it in oracle(2nd high sal)
Reply With Quote
Reply

  Geeks Talk > Databases > Data Warehousing


Thread Tools
Display Modes


Similar Threads

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


All times are GMT -4. The time now is 07:27 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Copyright © 2008 GeekInterview.com. All Rights Reserved