GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  Oracle  >  SQL
Go To First  |  Previous Question  |  Next Question 
 SQL  |  Question 106 of 171    Print  
what is difference between sub query and correlated sub query, Give the example for this.

  
Total Answers and Comments: 4 Last Update: February 12, 2008     Asked by: srinuv_11 
  
 Sponsored Links

 
 Best Rated Answer
Submitted by: srinivasarao
 
Hi
Corelated sub query will fire for each row and sub query will fire only once like that easy to remember
Srinivasa Rao K

Above answer was rated as good by the following members:
nixy11
November 28, 2006 04:32:00   #1  
MADHURI        

RE: what is difference between sub query and correlate...

CORRELATED SUBQUERIES: Is evaluated for each row processed by the Main query. Execute the Inner query based on the value fetched by the Outer query. Continues till all the values returned by the main query are matched. The INNER Query is driven by the OUTER Query

EX: SELECT empno fname sal deptid FROM emp e WHERE sal (SELECT AVG(sal) FROM emp WHERE deptid e.deptid)

The Correlated subquery specifically computes the avg(sal) for each department.

SUBQUERY: Runs first executed once returns values to be used by the MAIN Query. The OUTER Query is driven by the INNER QUERY


 
Is this answer useful? Yes | No
December 04, 2006 13:45:16   #2  
rampratap409 Member Since: September 2006   Contribution: 111    

RE: what is difference between sub query and correlate...

subquery: ( subquery executes only once and gives the output ot outer query then outer query executes)

select * from emp where deptno in ( select deptno from dept);

co-related query : ( co-related subquery executes for each row returned by main query )

select a.* from emp e

where deptno ( select deptno from emp a

where a.empno e.empno);

2. select e.* from emp e
where 3 > ( select count(*) from emp
where sal > e.sal)
order by sal desc


 
Is this answer useful? Yes | No
February 07, 2007 02:19:29   #3  
srinivasarao        

RE: what is difference between sub query and correlate...
Hi

Corelated sub query will fire for each row and sub query will fire only once like that easy to remember

Srinivasa Rao K

 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    
February 12, 2008 15:34:12   #4  
g_sidhu Member Since: August 2007   Contribution: 122    

RE: what is difference between sub query and correlated sub query, Give the example for this.

With a normal nested subquery the inner SELECT query runs first and executes once returning values to be used by the main query. A correlated subquery however executes once for each candidate row considered by the outer query. In other words the inner query is driven by the outer query.


 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape