Please enable Javascript to correctly display the contents on Dot Net Tricks!

Get nth highest and lowest salary of an employee

  Author : Shailendra Chauhan
Posted On : 31 Aug 2012
Total Views : 202,225   
Updated On : 24 Sep 2016
 

One student of me asked "how can we get nth highest and lowest salary on an employee ?". In this article I am going to expose, how can we achieve this in SQL Server.

Suppose we have employee name and salary as shown in below fig.

Query to get nth(3rd) Highest Salary

 Select TOP 1 Salary as '3rd Highest Salary' 
from (SELECT DISTINCT TOP 3 Salary from Employee ORDER BY Salary DESC) 
a ORDER BY Salary ASC 

Query to get nth(3rd) Lowest Salary

 Select TOP 1 Salary as '3rd Lowest Salary' 
from (SELECT DISTINCT TOP 3 Salary from Employee ORDER BY Salary ASC) 
a ORDER BY Salary DESC 
Summary

In this article, I explain how can you get nth highest and lowest salary of an employee. I hope after reading this article you will be able to do this. I would like to have feedback from my blog readers. Please post your feedback, question, or comments about this article.



Free Interview Books
 
COMMENTS (0)
3 APR
Master Class Fast Track MVC 5 with Angular2 Development (Online)

10:30 AM -03:30 PM IST (Fast Track)

Know More
1 APR
MEAN Stack 2 Development (Classroom)

11:00 AM-12:30 PM

Know More
1 APR
ASP.NET MVC with Angular2 Development (Classroom)

4:00 PM-5:30 PM

Know More
25 MAR
Xamarin Forms : Build Cross-platform Apps (Classroom)

8:00 AM-9:30AM

21 MAR
ASP.NET MVC with Angular2 Development (Online)

09:00 PM - 11:00 PM IST( TUS, THR, SAT)

6 MAR
ASP.NET MVC with Angular2 Development (Online)

07:00 AM - 09:00 AM IST( MON, WED, FRI)

25 FEB
ASP.NET MVC with Angular2 Development (Classroom)

05:00 PM-06:30 PM

31 JAN
ASP.NET MVC with Angular2 Development (Online)

07:00 AM-09:00 AM IST(Tuesday & Thursday)

30 JAN
NODEJS & MEAN Stack 2.x Development (Online)

09:00 PM-11:00 PM IST( MON, WED, FRI)

31 DEC
ASP.NET MVC with AngularJS Development (Classroom)

09:30 AM-11:00 AM

BROWSE BY CATEGORY
 
 
LIKE US ON FACEBOOK
 

Professional Speaks

+