In below
two scripts I have used the Use of = and
IN operator in 1 & 2 Query and in Third
query I have used the Exists Keyword for checking the performance issue and
when I seen the Execution Plan and the outcome is that Use the of = operator or
IN operator is less better than use of EXISTS Keyword.
Run the
below script and See the Execution plan.
USE
AdventureWorks
GO
--1) use of IN operator
SELECT * FROM HumanResources.Employee E
WHERE E.ManagerID in ( SELECT EmpAdd.EmployeeID
FROM
HumanResources.EmployeeAddress EmpAdd
WHERE EmpAdd.EmployeeID = E.ManagerID)
GO
--2) use of = operator
SELECT * FROM HumanResources.Employee E
WHERE E.ManagerID = ( SELECT EmpAdd.EmployeeID
FROM
HumanResources.EmployeeAddress EmpAdd
WHERE EmpAdd.EmployeeID = E.ManagerID)
GO
--3) use of exists Keyword
SELECT * FROM HumanResources.Employee E
WHERE EXISTS ( SELECT EmpAdd.EmployeeID
FROM
HumanResources.EmployeeAddress EmpAdd
WHERE EmpAdd.EmployeeID = E.ManagerID)
GO
Result: (Snap Shot of Execution Plan)
No comments:
Post a Comment
Thank You !!!!