1. We have moved to a new forum! There may be a few things not working properly so please let us know if you find a bug. Remember to use the bbCode [ sql ] tag for SQL statements.

how to find out the 4th highest value from the column?

Discussion in 'SQL - Questions and Answers' started by Anoj biradar, Mar 12, 2007.

  1. Anoj biradar Guest

    Dialect: SQL 92
  2. Dialect: Oracle
    SQL:

    SELECT ROWNUM AS RANK,D.SALARY
    FROM (SELECT MAX(SALARY) AS SALARY
    FROM EMPLOYEES
    ORDER BY SALARY DESC) D
    WHERE ROWNUM<=4
    MINUS
    SELECT ROWNUM AS RANK,D.SALARY
    FROM (SELECT MAX(SALARY) AS SALARY
    FROM EMPLOYEES
    ORDER BY SALARY DESC) D
    WHERE ROWNUM<=3

  3. Unregistered Guest

    You can do the same with

    SQL:
    select min(sal) from (select sal from emp where sal is not NULL order by sal desc) where rownum<=&rownum;
  4. deepak garg New Member

    You can calculate the 2,3,4 or the whichever highest value of a column you want to retrive:


    SQL:
    select min(sal) from (select sal from emp where sal is not NULL order by sal desc) where rownum<=&rownum;

Share This Page