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

0 votes
How would I go about querying for the second largest salary from all employees in my Employee table?
Feb 8, 2022 in Database by Neha
• 9,020 points
1,325 views

1 answer to this question.

0 votes

To find the 2nd largest salary from any employee table, you can use the following query:

SELECT distinct(sal)
FROM emp
ORDER BY sal DESC
LIMIT 1, 1;

*Here, emp is the employee table
           sal is the salary table

 WIth this query you can only get the second max salary.

And if you need any 3rd or 4th or Nth value, you can replace the first value followed by the LIMIT (n-1) 
ie. for 5th salary : LIMIT 4, 1;

answered Feb 8, 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,831 views
0 votes
0 answers

Find max and second max salary for a employee table MySQL

Assume you are given the following straightforward ...READ MORE

Aug 26, 2022 in Database by Kithuzzz
• 38,000 points
1,391 views