I didn't get the query for fetching the third largest salary from the employees table. How to find out the 3rd largest or many more salary from the employee table in SQL?
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
VulpesRank #55 · 29.2K reputationPosted Jan 16, 2015, 6:04 AM EST
http://dev.mysql.com/doc/refman/5.7/en/select.html
and I've noticed that the LIMIT clause has an option which takes 2 parameters rather than 1 which enables you to return a range of records. The first parameter is the offset from the first record (counting starts from 0 rather than 1) and the second parameter is the number of records to return.
So I think you should therefore be able to do this without using a sub-query at all:
SELECT DISTINCT salary FROM employees ORDER BY salary DESC LIMIT 2, 1
VulpesRank #55 · 29.2K reputationPosted Jan 16, 2015, 4:01 AM EST
http://www.c-sharpcorner.com/UploadFile/a20beb/find-the-3rd-or-nth-highest-salary-in-a-table-way-1/
Vikas Kumar Garg26 reputationPosted Jan 16, 2015, 5:06 AM EST
I am using this link to find the result.
I write query like this:-
select min(salary) from (select DISTINCT TOP 3 salary from employees ORDER BY salary DESC) as A
But when I run this query, it gives an error:-
1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '3 salary from employees ORDER BY salary DESC) as A' at line 1
VulpesRank #55 · 29.2K reputationPosted Jan 16, 2015, 5:27 AM EST
Vikas Kumar Garg26 reputationPosted Jan 16, 2015, 6:41 AM EST
Thanks for solving my problem.
VulpesRank #55 · 29.2K reputationPosted Jan 16, 2015, 6:44 AM EST
It would save a lot of hassle with this and similar problems :)
Anurag Singh131 reputationPosted Jan 21, 2015, 7:00 PM EST
Select TOP 1 Salary from (SELECT DISTINCT TOP 3 Salary from Employees ORDER
BY Salary DESC) a ORDER BY Salary ASC