0
How to know the emplyee who is having 2nd max salary?
9 Respostas
+ 3
The syntax depends on the DBMS you're using.
For SQL Server use TOP (posted earlier), Oracle uses ROWNUM clause, and in MySQL you can use LIMIT, like this:
SELECT name FROM [tablename]
ORDER BY salary DESC
LIMIT 1,1;
(gives you one result starting from the second place)
If you want just basic SQL which will work with any platform, you'll need to get creative, like Vijender did, except that if you want the name of the employee, then that's what you should query:
SELECT name from [tablename]
WHERE salary = (
SELECT MAX (salary) from [tablename] WHERE salary NOT IN (
SELECT MAX (salary) from [tablename]
)
);
+ 1
SELECT TOP 2 [column]
FROM [Table]
GROUP BY [column]
ORDER BY [column] DESC
OFFSET 1 ROWS
FETCH NEXT 1 ROWS ONLY
worked with sql server 2012
SQL Server (pre-2012):
SELECT MIN([column]) AS [column]
FROM (
SELECT TOP 2 [column]
FROM [Table]
GROUP BY [column]
ORDER BY [column] DESC
)
ref: http://stackoverflow.com/questions/32100/what-is-the-simplest-sql-query-to-find-the-second-largest-value
+ 1
(select the max salary in asc order) remove it and extract the first one after that... vijender has done that
+ 1
Select max(salary) from employees where salary <(select max(salary) from employees ;
0
sam ques?? answer plzz
0
select top 2 FirstName,salary From employe
order by salary desc
0
SELECT name FROM salaries ORDER BY salary DESC
0
Select salary
From employee
Limit 1,1
Order by salary desc
0
I think this may work.
SELECT FirstName, Salary FROM employees
WHERE Salary < (SELECT MAX(Salary) FROM employees)
ORDER BY Salary DESC;