Find Nth Highest Salary in SQL Server
Find Nth Highest Salary in SQL Server:
In this Post we try to find the nth max salary from sql data
base. Some time developer want to this type of query when they give more search
options in asp.net web site.
So here we give step by step process to find , 2, 3 …….highest
salary form sql table.
Find 2nd Highest Salary in SQL Server:
Write a SQL query to get the second highest salary from the
table above. Also write a query to find the nth highest salary in SQL, where n
can be any number.
SELECT MAX (Salary) FROM Employee WHERE Salary NOT IN
(SELECT MAX (Salary) FROM Employee)
Find the 3rd or Nth Highest Salary in a Table via SubQuery:
In that case we need to modify the above SQL Query. What we
need to do is to select the maximum Salary from the Salary table where Salary
is greater than maximum Salary from the Salary table. So the modified SQL Query
will be like:
Select MAX (Salary) from Salary where Salary< (select MAX
(Salary) from Salary)
The output will be 10000.00
So getting the second highest salary is simple enough. Now
we try to Getting the Nth Highest Salary.
SQL query to find find the nth highest salary:
SELECT TOP 1 Salary FROM
(
SELECT DISTINCT TOP (2) Salary FROM Salary ORDER BY
Salary DESC) Result ORDER BY Salary
But, the question was to get the nth highest salary. No
issues! We are done with it. Just replace 2 in the inner query with 3 to get
the 3rd highest salary, with 4 to get the 4th highest salary and so on.
Sql Server Interview Qus:
- SQL Server questions for interview
- Overview of Sql
- Sql server while loop
- Continue Statement in sql
- interview Part2
- interview Part3
- interview Part4
- SQL-QUERY TYPES, ALIASES, JOINS, CLAUSES, FUNCTIONS
- Sql-determine the version and edition of SQL Server
Jquery Related Other post:
- Example jQuery Validate on CheckBoxList using C#
- How do you do html text encodes using JavaScript
- Check Uncheck all html CheckBox controls using jQuery:
- Check Uncheck all asp.net CheckBox in asp.net using jQuery
- Example of jQuery Validate on Radiobuttonlist in Asp.Net using C#
- Validate ASP.Net RadioButtonList using JavaScript Example
- Example of jQuery Validate on Radiobuttonlist in Asp.Net using C#
- Cropping image using jQuery in asp.net
- Displaying the textbox value in javascript Messagebox
- Get selected radio button values using JQuery
- fill data into Dropdown list by using Jquery
- jQuery Crop Image in Asp.net using Jcrop jQuery
- Example jQuery Validate on CheckBoxList using C#
- Check Uncheck all asp.net CheckBox in asp.net using jQuery
- Check Uncheck all html CheckBox controls using jQuery:
- Asp.net CheckBoxList using jQuery.
- Get selected radio button values using JQuery.
- Limit Number of Characters in a TextArea using jQuery
- Limitation of Characters in Textbox or TextArea in asp.net using jquery:
Comments
Post a Comment