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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
VulpesPosted Jan 16, 2015, 11:04 AM
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
Anurag SinghPosted Jan 22, 2015, 12:00 AM
Select TOP 1 Salary from (SELECT DISTINCT TOP 3 Salary from Employees ORDER
BY Salary DESC) a ORDER BY Salary ASC
VulpesPosted Jan 16, 2015, 11:44 AM
It would save a lot of hassle with this and similar problems :)
Vikas Kumar GargPosted Jan 16, 2015, 11:41 AM
Thanks for solving my problem.
VulpesPosted Jan 16, 2015, 10:27 AM
Vikas Kumar GargPosted Jan 16, 2015, 10:06 AM
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
VulpesPosted Jan 16, 2015, 9:01 AM
http://www.c-sharpcorner.com/UploadFile/a20beb/find-the-3rd-or-nth-highest-salary-in-a-table-way-1/