Easy Way:How to find 3rd higest salary in sql server

Find 3rd highest salary in SQL server

In this tutorial, I am going to show how we can find the 3rd highest salary in SQL Server. In below, the method I want to show you a very easy method so it will help to understand better. The method will take three step so please understand every step carefully.

create table EmployeeSalary 
   ID int identity primary key, 
   Name varchar(20), 
   Salary Decimal  

Insert into EmployeeSalary(Name,Salary)values('Ram',21000) 
Insert into EmployeeSalary(Name,Salary)values('Jhon',50000) 
Insert into EmployeeSalary(Name,Salary)values('Simant',40000) 
Insert into EmployeeSalary(Name,Salary)values('Tom',35000) 
Insert into EmployeeSalary(Name,Salary)values('Alia',25000) 
Insert into EmployeeSalary(Name,Salary)values('Mohan',22000) 
Insert into EmployeeSalary(Name,Salary)values('Raj',23000)


#Step 1:
In this query, I execute to show the record of  EmployeeSalary table

 * from EmployeeSalary

How to find 3rd higest salary in sql server
3rd higest salary in sql server

#Step 2: Now, Firstly find the top 3 salaries with descending order

Select  top 3 Name,Salary from EmployeeSalary order by salary desc

How to find 3rd higest salary in sql server
3rd higest salary

Let suppose the above record is a table, now we need to find a salary from current table record.

#Step 3: Find the top 1 record in ascending order from the current record 

select top 1 Name,Salary from (select  top 3 Name,Salary from EmployeeSalary order by salary desc) as T  order by salary asc

How to find 3rd higest salary in sql server
3rd highest salary 

Finally, we find the 3rd highest salary from SQL Server table


Post a Comment

Post a Comment (0)

Previous Post Next Post