A correlated subquery is an inner subquery which is referenced by the main outer query such that the inner query is considered as being executed repeatedly.
Example:
----Example of Correlated SubqueriesUSE AdventureWorks;GOSELECT e.EmployeeID FROM HumanResources.Employee eWHERE e.ContactID IN(SELECT c.ContactIDFROM Person.Contact c WHERE MONTH(c.ModifiedDate) = MONTH(e.ModifiedDate))GOHere e.ModifiedDate-->Outer Query field refers in Inner Query.A noncorrelated subquery is subquery that is independent of the outer query and it can executed on its own without relying on main outer query.Example:
----Example of Noncorrelated SubqueriesUSE AdventureWorks;GOSELECT e.EmployeeIDFROM HumanResources.Employee eWHERE e.ContactID IN(SELECT c.ContactIDFROM Person.Contact cWHERE c.Title = 'Mr.')GOHere 'Mr.'--->Outer Query field doesn't refers in Inner Query.
No comments:
Post a Comment