3 ways to find second highest salary ORACLE SQL

Solution 1 :

WITH t
     AS (SELECT sal, ename, DENSE_RANK () OVER (ORDER BY sal DESC) AS rnk
           FROM emp)
SELECT sal, ename
  FROM t
 WHERE rnk IN (2);

--WHERE Rnk IN (1,2,3);

OR

SELECT ename, sal, RANK
  FROM (SELECT ename, sal, DENSE_RANK () OVER (ORDER BY sal DESC) RANK
          FROM emp)
 WHERE RANK = 2

Solution 2 :

SELECT MAX(SAL) FROM EMP WHERE SAL NOT IN (SELECT MAX(SAL) FROM EMP)

Solution 3 :

SELECT MAX (sal)
  FROM emp
 WHERE sal IN (SELECT sal FROM emp
               MINUS
               SELECT MAX (sal) FROM emp)