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 in Database by Neha
• 8,940 points
131 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 by Vaani
• 7,020 points

Related Questions In Database

0 votes
0 answers
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 in Database by Kithuzzz
• 20,660 points
154 views
0 votes
1 answer

How will I get all the rows from my table where name starts with 's' and ending with 'I'?

Hi Santanu, I understand your problem, You can try ...READ MORE

answered May 28, 2019 in Database by sampriti
• 1,120 points
778 views
0 votes
0 answers

How can I get column names from a table in SQL Server?

I want to search for every column's ...READ MORE

Sep 3 in Database by Kithuzzz
• 20,660 points
56 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 in Database by Kithuzzz
• 20,660 points
46 views
0 votes
1 answer
0 votes
1 answer

How to change the default value and to alter a column in sql?

Hi, You can try this: ALTER TABLE foobar_data CHANGE ...READ MORE

answered Jun 24, 2019 in Big Data Hadoop by Gitika
• 65,890 points
547 views
0 votes
1 answer

What is an index in SQL?

An index is used to speed up ...READ MORE

answered Feb 3 in Database by Vaani
• 7,020 points
117 views
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
708 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 in Database by Vaani
• 7,020 points
168 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