Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

How would I go about querying for the second largest salary from all employees in my Employee table?

like image 326
Dinesh Avatar asked Jan 29 '10 06:01

Dinesh


People also ask

How do you find the 2nd highest salary?

We can nest the above query to find the second largest salary. select *from employee group by salary order by salary desc limit 1,1; There are other ways : SELECT name, MAX(salary) AS salary FROM employee WHERE salary IN (SELECT salary FROM employee MINUS SELECT MAX(salary) FROM employee);

How do you retrieve 2nd 3rd or nth highest salary from employee table?

Here is a way to do this task using dense_rank() function. Query : select * from( select ename, sal, dense_rank() over(order by sal desc)r from Employee) where r=&n; To find to the 2nd highest sal set n = 2 To find 3rd highest sal set n = 3 and so on.

How do I find the second highest value in SQL?

SELECT MAX (column_name) FROM table_name WHERE column_name NOT IN (SELECT Max (column_name) FROM table_name); First we selected the max from that column in the table then we searched for the max value again in that column with excluding the max value which has already been found, so it results in the 2nd maximum value.


1 Answers

Try this:

SELECT max(salary) FROM emptable WHERE salary < (SELECT max(salary)                 FROM emptable); 
like image 79
deepa Avatar answered Sep 29 '22 17:09

deepa