how to find max salary in sql code example

Example 1: min and max salary and name in sql

SELECT FIRST_NAME , SALARY
FROM EMPLOYEES
WHERE SALARY IN (SELECT MAX(SALARY)AS RESULT FROM EMPLOYEES
UNION
SELECT MIN(SALARY)AS RESULT FROM EMPLOYEES);

Example 2: how to find max and min salary in sql

SELECT MAX(salary), MIN(salary) FROM employees;

Example 3: second max salary in sql

SELECT MAX(SALARY) 'SECOND_MAX' FROM EMPLOYEES
WHERE SALARY <> (SELECT MAX(SALARY) FROM EMPLOYEES);

Example 4: first max salary in sql

SELECT first-name
FROM employees
WHERE salary = (SELECT MAX(salary) FROM employees);

Example 5: sql highest salary by location

/*  Highest salary by Department/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
)

Tags:

Sql Example