+ 1

How can I check second highest salary in emp_sal

9th Dec 2017, 3:58 AM
pksardar kumar
pksardar kumar - avatar
2 ответов
+ 5
Assuming the table "emp_sal" and the field "salary"; you can try the following query: [MySQL] SELECT salary FROM emp_sal WHERE salary < MAX(salary) ORDER BY salary DESC LIMIT 1; [Microsoft SQL Server] SELECT TOP 1 salary FROM emp_sal WHERE salary < MAX(salary) ORDER BY salary DESC; [Oracle] SELECT salary FROM emp_sal WHERE salary < MAX(salary) AND ROWNUM < 2 ORDER BY salary DESC; Hth, cmiiw
9th Dec 2017, 5:20 AM
Ipang
+ 3
select max(emp_sal) from employee where emp_sal<(select max(emp_sal) from employee); To go further down your list, you need to repeat the where condition continuously.
9th Dec 2017, 5:11 AM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar