how to get max salary in each department in sql code example
Example 1: second max salary in sql
SELECT MAX(SALARY) 'SECOND_MAX' FROM EMPLOYEES
WHERE SALARY <> (SELECT MAX(SALARY) FROM EMPLOYEES);
Example 2: 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 3: how to find max and min salary in sql
SELECT MAX(SALARY) FROM EMPLOYEES
UNION
SELECT MIN(SALARY) FROM EMPLOYEES;