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

Showing Answers 1 - 17 of 17 Answers

Rama Krishna,Yerra

  • Aug 2nd, 2006
 

1)By Using Rownum we can do the same mechanisam..

Select rownum,empno,ename,sal from(select rownum,empno,ename,sal from emp order by sal) having rownum=&n;

2) select empno,sal from emp e where &n>(select min(sal) from emp where sa l<e.sal);

Thanks&Regds

Ramki,TCS,DP HYd

  Was this answer useful?  Yes

Raveendra B N

  • Oct 13th, 2006
 

select value from <table name> a

where n = (select count(distinct value)

from <table name> b

where a.value <= b.value)

  Was this answer useful?  Yes

tina_0091

  • Apr 3rd, 2007
 

Use the top-analysis feature which introduce from oracle 8i:

SELECT rownum, empno, ename, sal
FROM (SELECT empno, ename, sal from emp 
           ORDER BY sal )
WHERE rownum < n; (n=any valid integer)

Thanks,
Tina K.

  Was this answer useful?  Yes

soumyapradh

  • Jul 21st, 2007
 


Try this one

SELECT LEVEL, MIN(Sal)
FROM Emp
WHERE LEVEL = &LevelNo
CONNECT BY PRIOR Sal < Sal
GROUP BY LEVEL
/

  Was this answer useful?  Yes

Ishita

  • Oct 4th, 2007
 

Easiest way

select top 1 name from emp where name>(select min(name) from emp) order by name

Ishita.

  Was this answer useful?  Yes

NITYANAND

  • Oct 7th, 2007
 

TO find out nth LOWEST value, e.g. salary from emp table without using ROWNUM & DESC/ASC

SELECT DISTINCT (a.sal) FROM EMP A
WHERE &N = (SELECT COUNT (DISTINCT (b.sal))
                       FROM EMP B
                       WHERE a.sal >= b.sal);

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions