Thoughts on Sub queries


There are two types of sub queries :

1. Non correlated

2. Correlated

Correlated – This is a situation where the Sub Query uses a Col or more Col’s from the outer query for results

Select * from HumanResources.Employee as E 
where exists
(
select * from HumanResources.EmployeeAddress EA
where E.EmployeeID=EA.EmployeeID
)

Non Correlated – This is a situation where the sub query doesn’t use the outer query Col or Col’s.

Select * from HumanResources.Employee as E
where E.EmployeeID IN
(Select EmployeeID
from HumanResources.EmployeeAddress
)

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s