Blog author:
Sourabh07 | Posted on: 10/25/2012 | Category:
SQL Server Blogs | Views: 544 | Status:
[Member] |
Points: 75
|
Alert Moderator
Download source file
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: