How can I check second highest salary in emp_sal | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How can I check second highest salary in emp_sal

9th Dec 2017, 3:58 AM
pksardar kumar
pksardar kumar - avatar
2 Answers
+ 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
Kinshuk Vasisht
Kinshuk Vasisht - avatar