How To Find Nth Salary Of Employee

The question always asked during interview is how to find Nth salary of Employee

# Let we consider a table Employee_Salary contains the columns Emp_Id,Emp_Name,Emp_Salary.


Employee_Salary
 Emp_Name
 Emp_Id
 Emp_Salary
 Rakesh
 001
 8000
 Ashish
 002
 10000
 Shalu
 003
 11000
 Mohit
 004
 12000
 Anurag
 005
 13000
 Bhanu
 006
 14000



## Now we go through Nth Salary

* SELECT  Top 1 Emp_Salary FROM  (Select  Top Nth  Emp_Salary form  Employee_Salary           order   by  Emp_Salary desc) as EmpSalary order by Emp_Salary  


Example

#  SELECT  Top 1 Emp_Salary FROM  (Select  Top 3  Emp_Salary form  Employee_Salary           order   by  Emp_Salary desc) as EmpSalary order by Emp_Salary  

/// output is 12000

Note:



*  Here Nth is any number of which you want to find out the salary.
*  Here EmpSalary is an alias.
*  Top Nth indicates the number (Ex. 1,2,3,4,5,......).



///////ouput is nth number of Emp_Salary 






Comments

Post a Comment

Popular posts from this blog

How To Create Table In MSSQL

How To Find Second Max Salary Of Employee