Correlated subquery and nested query

Posted by Karthikanbarasan under Sql Server on 2/4/2011 | Points: 10 | Views : 21635 | Status : [Member] [Moderator] [Microsoft_MVP] [MVP] | Replies : 2
Can any one point the difference between Correlated subquery and nested query with an example clearly

Thanks
Karthik
www.f5Debug.net



Responses

Posted by: T.saravanan on: 2/5/2011 [Member] [MVP] Silver | Points: 25

Up
0
Down
Hi Karthik,

Correlated SubQuery : Inner query is depend upon the outer query.
Ex: Select A.nID,A.sName from table1 A where A.sCity = (Select sCityName from table2 where nId = A.nID)


Nested Query: There is no relationship between inner and outer query.
Ex: Select nID,sName from table1  where sCity in (Select distinct sCityName from table2)


For more info...http://www.databasejournal.com/features/mssql/article.php/3485291/Using-a-Correlated-Subquery-in-a-T-SQL-Statement.htm
http://www.dba-sql-server.com/sql_server_tips/t_super_sql_411_subqueries.htm

Cheers :)

Thanks,
T.Saravanan

Karthikanbarasan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Karthikanbarasan on: 2/5/2011 [Member] [Moderator] [Microsoft_MVP] [MVP] Silver | Points: 25

Up
0
Down
Thanks saravanan

Thanks
Karthik
www.f5Debug.net

Karthikanbarasan, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response