SQL to Find the 3rd MAX salary
[code language=”sql”]
SELECT DISTINCT sal
FROM emp e1
WHERE 3 =
(SELECT count(DISTINCT sal)
FROM emp e2
WHERE e1.sal <= e2.sal);
[/code]
SQL to Find the 3rd MIN salary
[code language=”sql”]
SELECT DISTINCT sal
FROM emp e1
WHERE 3 =
(SELECT count(DISTINCT sal)
FROM emp e2
WHERE e1.sal >= e2.sal);
[/code]
Click here for more Complex SQL Queries.
Related
