Hi Frndz,
Functionality: Corelated Query and Sub Query
CoRelated Query
A correlated subquery is a subquery that is evaluated once for each row of the outer query.
Correlated query excuted once the row of the outer query.
Corelatd query is more faster then join.
Diffrence Between Corelated sub Query and sub Query
Corelated subquery make refrence using correlation variable, to the outer query
Folloiwng example include correlated and simple subquery.
select studentname ,
( select avg(studentmark) from students where class = t1.class ) as classaverage ,
( select avg(studentmark) from students ) as schoolaverage from students t1
When return classaverage then this corelated becasue t1 is corelation vaiable refrence using in sub query
When schoolaverage then there is no any refrence in sub query
Hope this helpful!
Thanks