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  >  Tech FAQs  >  SQL
Go To First  |  Previous Question  |  Next Question 
 SQL  |  Question 178 of 190    Print  
Correlated subquery
display the 5th lowest sal from emp table using Correlated subquery


  
Total Answers and Comments: 6 Last Update: October 11, 2008     Asked by: lalit.eng.kumar 
  
 Sponsored Links

 
 Best Rated Answer
Submitted by: tariq_oracle
 
select * from emp a
where 5=
(select count(distinct sal) from emp
where a.sal>=b.sal)

Above answer was rated as good by the following members:
elay_81
May 09, 2008 23:48:09   #1  
tariq_oracle Member Since: April 2008   Contribution: 11    

RE: Correlated subquery
select * from emp a
where 5=
(select count(distinct sal) from emp
where a.sal>=b.sal)

 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    
June 15, 2008 07:08:38   #2  
pvsp.indian Member Since: March 2008   Contribution: 2    

RE: Correlated subquery
(select * from(select * from emp order by sal) where rownum<6) minus (select * from(select * from emp order by sal) where rownum<5)
 
Is this answer useful? Yes | No
September 03, 2008 03:20:05   #3  
Praveen2384 Member Since: September 2008   Contribution: 7    

RE: Correlated subquery
select sal from emp_table where sal in (select sal from emp_table order by sal) where rownum>N-5;
 
Is this answer useful? Yes | No
September 04, 2008 11:26:31   #4  
puspanjali Member Since: September 2008   Contribution: 1    

RE: Correlated subquery

SELECT sal FROM ( SELECT ROWNUM srno , sal FROM ( SELECT DISTINCT sal

FROM emp

ORDER BY ASC ) ) a WHERE a.srno = &N ;


 
Is this answer useful? Yes | No
October 11, 2008 03:57:36   #5  
sureshkumar.mtech Member Since: May 2008   Contribution: 35    

RE: Correlated subquery

SQL> select x.* from (
  2  select last_name, salary, rank() over(order by salary desc) as high_salary
  3  from employee)x where x.high_salary = 5;

LAST_NAME      SALARY HIGH_SALARY
---------- ---------- -----------
Martin        1234.56           5

SQL> select x.* from (
  2  select last_name,salary, row_number() over(order by salary desc) as num
  3  from employee)x where x.num = 5;

LAST_NAME      SALARY        NUM
---------- ---------- ----------
Martin        1234.56          5


 
Is this answer useful? Yes | No
October 11, 2008 04:02:10   #6  
sureshkumar.mtech Member Since: May 2008   Contribution: 35    

RE: Correlated subquery

display the 5th lowest sal from emp table using Correlated subquery

table have data:
----------------

SQL> select last_name,salary from employee order by salary asc;

LAST_NAME      SALARY
---------- ----------
Cat           1232.78
Martin        1234.56
Black         2334.78
Rice          2344.78
Smith         6544.78
Mathews       6661.78

6 rows selected.

SQL>

select x.* from (
select last_name, salary, rank() over(order by salary asc) as high_salary
from employee)x where x.high_salary = 5;

LAST_NAME      SALARY HIGH_SALARY
---------- ---------- -----------
Martin        1234.56           5

select x.* from (
select last_name,salary, row_number() over(order by salary asc) as num
from employee)x where x.num = 5;

LAST_NAME      SALARY        NUM
---------- ---------- ----------
Martin        1234.56          5


 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 




About Us  |   Privacy Policy  |   Terms and Conditions  |   Contact  |   Site Map  |   Add Question  |   Propose Category  |   RSS Feeds  |   Articles Sitemap  |   Site Updates  |   Add Resource

Copyright © 2005 - 2008 GeekInterview.com. All Rights Reserved
Page copy protected against web site content infringement by Copyscape