Congratulations to all monthly winners of May 2013 !!! They have won INR 2900 cash and INR 27497 worth prize.
DotNetFunda.Com Logo
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 13693 |  Welcome, Guest!   Register  Login
 Home > Blogs > SQL Server > Finding Nth Highest Salary from the Table. ...
Sourabh07

Finding Nth Highest Salary from the Table.

 Blog author: Sourabh07 | Posted on: 10/25/2012 | Category: SQL Server Blogs | Views: 544 | Status: [Member] | Points: 75 | Alert Moderator     Download source file
Ads

The most frequent question asked in an Interview is

a) To find the highest salary of an employee

b) to find second highest salary of an employee

So, in order to overcome these type of questions, I tried to make a generic code for finding Nth highest salary from any table.

Here, N can be 1,2,3,4,............N

Select top(1) * from Table_Name  
where Unique_Id_Column In (
         Select top(N) Unique_Id_Column from Table_Name Order by Salary_Value_Column desc
      ) 
Order by Salary_Value_Column

Also, find the attached file as an example of this query.




Sourabh07
Found interesting? Add this to:



 More Blogs from Sourabh07

 More ...

About Sourabh 07

Experience:1 year(s)
Home page:http://www.dotnetfunda.com
Member since:Saturday, October 13, 2012
Level:Starter
Status: [Member]
Biography:Dot Net Developer

 Responses

Kollikr
Posted by: Kollikr | Posted on: 10/26/2012 | Level: Starter | Status: [Member] | Points: 15 | Alert Moderator 

Good. But can you try without using top?

>> Write Response - Respond to this post and get points

More Blogs

About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 6/20/2013 2:16:37 AM