Write a sql query to find the second maximum element from a table.

This article is tagged with: Write a sql query to find the second maximum element from a table. and mysql

Write a SQL query to find the second maximum element from a table.

SELECT name, MAX(salary) AS salary
FROM employee
WHERE salary < (SELECT MAX(salary)
FROM employee);

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
)

second height salary mysql

Both options you find max as a subset and then exclude from main select
sql> SELECT MAX( col ) FROM table
WHERE col < ( SELECT MAX( col ) FROM table);
sql> SELECT MAX(col) FROM table
WHERE col NOT IN (SELECT MAX(col) FROM table);

This article is tagged with: Write a sql query to find the second maximum element from a table. and mysql