0

How to know the emplyee who is having 2nd max salary?

27th Jul 2016, 2:05 PM
Krishna Kulkarni
Krishna Kulkarni - avatar
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] ) );
1st Aug 2016, 9:25 AM
MrAwesome
+ 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
28th Jul 2016, 3:58 PM
ashwath nm
ashwath nm - avatar
+ 1
(select the max salary in asc order) remove it and extract the first one after that... vijender has done that
30th Jul 2016, 3:39 AM
ANIMESH GUPTA
ANIMESH GUPTA - avatar
+ 1
Select max(salary) from employees where salary <(select max(salary) from employees ;
23rd Aug 2016, 10:27 AM
Bala Murali Krishna
Bala Murali Krishna - avatar
0
sam ques?? answer plzz
28th Jul 2016, 2:40 AM
sudhakar sharma
sudhakar sharma - avatar
0
select top 2 FirstName,salary From employe order by salary desc
28th Jul 2016, 2:26 PM
mohamed
0
SELECT name FROM salaries ORDER BY salary DESC
28th Jul 2016, 2:40 PM
Brian Upsher
Brian Upsher - avatar
0
Select salary From employee Limit 1,1 Order by salary desc
15th Sep 2016, 7:36 AM
Hardik Masalawala
Hardik Masalawala  - avatar
0
I think this may work. SELECT FirstName, Salary FROM employees WHERE Salary < (SELECT MAX(Salary) FROM employees) ORDER BY Salary DESC;
4th Sep 2020, 4:36 PM
Ravshan Muso
Ravshan Muso - avatar