how to add employee name and department name in this query SELECT (SELECT MAX(SALARY) FROM EMPLOYEE) MAX SALARY, (SELECT MAX(SALARY) FROM EMPLOYEE WHERE SALARY NOT IN (SELECT MAX(SALARY) FROM EMPLOYEE )) as 2ND MAX SALARY; code example
Example 1: sql find second highest salary employee
select sal, ename
from emp
where sal =
(
select max(sal) from emp where sal <
(select max(sal) from emp)
)
select *
from
(
select ename, sal, dense_rank() over(order by sal desc) rank
from emp
)
where rank =2;
Example 2: sql highest salary by location
SELECT e.ename, e.sal, e.deptno, d.loc
FROM emp e
JOIN dept d
ON e.deptno = d.deptno
WHERE e.sal in
(
select max(sal)
from emp
group by deptno
)