How to find third or n maximum salary from salary table

0 votes
How can I efficiently retrieve the third or nth highest salary in the salary table (EmpID, EmpName, EmpSalary)?
Sep 18 in Database by Kithuzzz
• 12,240 points
18 views

1 answer to this question.

0 votes

Use ROW_NUMBER(if you want a single) or DENSE_RANK(for all related rows):

WITH CTE AS
(
    SELECT EmpID, EmpName, EmpSalary,
           RN = ROW_NUMBER() OVER (ORDER BY EmpSalary DESC)
    FROM dbo.Salary
)
SELECT EmpID, EmpName, EmpSalary
FROM CTE
WHERE RN = @NthRow
answered Sep 19 by narikkadan
• 20,880 points

Related Questions In Database

0 votes
1 answer
0 votes
1 answer

Which SQL query is used to find Nth highest salary from a salary table

If you want to find nth Salary ...READ MORE

answered Feb 14 in Database by Vaani
• 7,020 points
472 views
0 votes
0 answers
0 votes
1 answer

What is the SQL query to get the third highest salary of an employee from employee_table

You can try out something like this: SELECT ...READ MORE

answered Sep 27, 2018 in Database by Sahiti
• 6,380 points
7,595 views
0 votes
1 answer

Rename column SQL Server 2008

Use sp_rename EXEC sp_RENAME 'TableName.PreviousColumnName' , 'NewColumnName', 'COLUMN' See: SQL SERVER ...READ MORE

answered Feb 23 in Database by Vaani
• 7,020 points
53 views
0 votes
0 answers

How to update Identity Column in SQL Server?

With 200 records currently, I want to ...READ MORE

Aug 9 in Database by Kithuzzz
• 12,240 points
174 views
0 votes
0 answers

Simple DateTime sql query

How do I query the DateTime database ...READ MORE

Aug 12 in Database by Kithuzzz
• 12,240 points
23 views
0 votes
0 answers

Calculate time difference in minutes in SQL Server

I require the minutes-based time difference between ...READ MORE

Aug 13 in Database by Kithuzzz
• 12,240 points
127 views
0 votes
1 answer

How to find top three highest salary in emp table in oracle?

Use this: SELECT *FROM ...READ MORE

answered Sep 18 in Database by narikkadan
• 20,880 points
60 views
0 votes
1 answer

How to select from multiple tables without a JOIN ?

Try this: SELECT ... FROM ( SELECT ...READ MORE

answered Sep 12 in Database by narikkadan
• 20,880 points
47 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP