GeekInterview.com
   Home |  Tech FAQ  |   Interview Questions |  Placement Papers |  Tech Articles |  Learn |  Freelance Projects |  Online Testing |  Geeks Talk |  Job Postings |  Knowledge Base | Site Search |  Add/Ask Question

  GeekInterview.com  >  Interview Questions  >  Oracle  >  SQL

 Print  |  
Question:  minvalue.sql Select the Nth lowest value from a table


Answer:
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


October 10, 2007 02:47:21 #7
 NITYANAND   Member Since: Visitor    Total Comments: N/A 

RE: minvalue.sql Select the Nth lowest value from a ta...
 
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);
     

 

Back To Question