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

Get nth highest and lowest salary of an employee

  Author : Shailendra Chauhan
Updated On : 24 Sep 2016
Total Views : 195,921   
Support : SQL Server 2005,2008,2012
 

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.

YOU MIGHT LIKE
Free Interview Books
 
COMMENTS (0)
14 DEC
ASP.NET MVC with AngularJS Development (online)

MON-FRI 07:30 AM- 09:00 AM IST

Know More
5 DEC
AngularJS Development (online)

Mon - Fri     6:30 AM-7:30 AM IST

3 DEC
AngularJS Development (offline)

SAT,SUN     11:00 AM-12:30 PM IST

3 DEC
MEAN Stack Development (offline)

Sat, Sun     (09:30 AM-11:00 AM IST)

26 NOV
ASP.NET MVC with AngularJS Development (offline)

(SAT,SUN)     03:30 PM-05:00 PM IST

24 NOV
ASP.NET MVC with AngularJS Development (online)

MON-FRI     09:30 PM-11:00 PM IST

12 NOV
ASP.NET MVC with AngularJS Development (offline)

SAT,SUN     08:00 AM-09:30 AM

3 NOV
ASP.NET MVC with AngularJS Development (online)

MON-FRI     07:30 AM-09:00 AM IST

25 OCT
.NET Development (offline)

Mon-Fri     9:00 AM-11:00 AM IST

BROWSE BY CATEGORY
 
RECENT ARTICLES
SUBSCRIBE TO LATEST NEWS
 
LIKE US ON FACEBOOK
 

Professional Speaks

+