query to find max salary code example
Example 1: how to get max salary in each department in sql
SELECT firstname, MAX(salary)
FROM department d LEFT OUTER JOIN employee e
ON (d.department_id = e.department_id)
GROUP BY department_id;
Example 2: how to find max and min salary in sql
SELECT MAX(SALARY) FROM EMPLOYEES
UNION
SELECT MIN(SALARY) FROM EMPLOYEES;
Example 3: 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
)