Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 explain subquery vs correlated subquery

Author  Topic 

gnanasekar
Starting Member

6 Posts

Posted - 2011-08-09 : 08:25:17
can u explain difference between correlated subquery vs sub query

in my interview i explain like this

In sub query the inner query is executed only once. Depeding upon the results of inner query , outer query is evaluated.

In correlated subquery the inner query is evaluated once for each row processed by the parent statement or outer query.

LIKE THIS THEY R NOT SATISFY MY ANS SO PLZ EXPLAIN IT

Ghanta
Yak Posting Veteran

96 Posts

Posted - 2011-08-09 : 09:31:58
If you google it you will get all the info; however, your definition looks good.

quote:
Originally posted by gnanasekar

can u explain difference between correlated subquery vs sub query

in my interview i explain like this

In sub query the inner query is executed only once. Depeding upon the results of inner query , outer query is evaluated.

In correlated subquery the inner query is evaluated once for each row processed by the parent statement or outer query.

LIKE THIS THEY R NOT SATISFY MY ANS SO PLZ EXPLAIN IT

Go to Top of Page

GilaMonster
Master Smack Fu Yak Hacker

4507 Posts

Posted - 2011-08-09 : 10:16:09
quote:
Originally posted by gnanasekar

In correlated subquery the inner query is evaluated once for each row processed by the parent statement or outer query.


It is not, and it's trivial to test and see that a correlated subquery does not necessarily run once for each row of the outer query. There are two special cases where it does, but the majority of the time it does not.

The actual definition of a correlated subquery is a subquery that contains a reference to a column in the outer query.

--
Gail Shaw
SQL Server MVP
Go to Top of Page
   

- Advertisement -