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

0 votes
Can someone please help me to find out nth highest salary from the salary table in MYSQL?
Feb 14, 2022 in Database by Neha
• 9,020 points
2,852 views

1 answer to this question.

0 votes

If you want to find nth Salary from a table where n can be any number,

Query for finding the nth Salary:

SELECT DISTINCT Salary FROM tblemployees ORDER BY Salary DESC LIMIT 1 OFFSET (n-1)

If you want to find 5th highest salary, your query should look like :

SELECT DISTINCT Salary FROM tblemployees ORDER BY Salary DESC LIMIT 1 OFFSET 4

Note: OFFSET starts from 0th position, and hence use N-1 rule here

answered Feb 14, 2022 by Vaani
• 7,070 points

Related Questions In Database

0 votes
0 answers

How to fetch the nth highest salary from a table without using TOP and sub-query?

I was recently requested to create a ...READ MORE

Aug 25, 2022 in Database by Kithuzzz
• 38,000 points
1,381 views
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,370 points
12,622 views
0 votes
0 answers

How to create a table from select query result in SQL Server 2008

I tried to build a table from ...READ MORE

Sep 2, 2022 in Database by Kithuzzz
• 38,000 points
853 views
0 votes
2 answers

Write a SQL query to find the names of employees that begin with ‘S’

Select ename From emp Where ename like"s%"; READ MORE

answered Oct 7, 2021 in Database by anonymous
27,101 views
0 votes
1 answer

SQL query to find third highest salary in company

The easiest way to work this out ...READ MORE

answered Feb 21, 2022 in Database by Neha
• 9,020 points
51,427 views
0 votes
0 answers

Creating a search form in PHP [duplicate]

I am working on a function where ...READ MORE

Jun 9, 2022 in PHP by Kichu
• 19,040 points
415 views
0 votes
0 answers

How do I list all the columns in a table?

For the various popular database systems, how ...READ MORE

Aug 9, 2022 in Database by Kithuzzz
• 38,000 points
540 views
0 votes
0 answers

How to convert date into timestamp in SQL query?

I'm attempting to move data from the ...READ MORE

Aug 19, 2022 in Database by Kithuzzz
• 38,000 points
1,682 views
0 votes
1 answer

How would I find the second largest salary from a employee table? [closed]

To find the 2nd largest salary from ...READ MORE

answered Feb 8, 2022 in Database by Vaani
• 7,070 points
921 views
0 votes
1 answer

How do I UPDATE from a SELECT in SQL Server?

MERGE INTO YourTable T USING ...READ MORE

answered Feb 3, 2022 in Database by Vaani
• 7,070 points
819 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