Difference between Subquery and Correlated Subquery

前端 未结 7 820
Happy的楠姐
Happy的楠姐 2020-11-28 05:10

Is the following piece of SQL Query a normal query or a Correlated Subquery ??

SELECT UserID,
       FirstName,
       LastName,
       DOB,
       GFName,
          


        
7条回答
  •  Happy的楠姐
    2020-11-28 05:54

    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

提交回复
热议问题