Answered Questions

  • minvalue.sql Select the Nth lowest value from a table

    select level, min('col_name') from my_table where level = '&n' connect by prior ('col_name') <'col_name')group by level;Example:Given a table called emp with the following columns:-- id number-- name varchar2(20)-- sal number---- For the second lowest salary:-- select level, min(sal) from emp-- where level=2-- connect by prior sal < sal-- group by level

    NITYANAND

    • Oct 7th, 2007

    TO find out nth LOWEST value, e.g. salary from emp table without using ROWNUM & DESC/ASCSELECT DISTINCT (a.sal) FROM EMP A WHERE &N = (SELECT COUNT (DISTINCT (b.sal))     &...

    Ishita

    • Oct 4th, 2007

    Easiest wayselect top 1 name from emp where name>(select min(name) from emp) order by nameIshita.

  • Find out nth highest salary from emp table

    SELECT DISTINCT (a.sal) FROM EMP A WHERE &N = (SELECT COUNT (DISTINCT (b.sal)) FROM EMP B WHERE a.sal < = b.sal);For Eg:-Enter value for n: 2SAL---------3700

    Silpa

    • Apr 18th, 2018

    Select employee_id,salary, rownumber from (Select employee_id,salary,row_number() over (order by salary desc) as rownumber from hr.employees)
    where rownumber = n;

    VISHWA

    • Mar 10th, 2018

    Here for ROWNUM =1 it will work but for ROWNUM = 2 and so on it will not work.