masterchicker
Programmer
What is the difference between the IN and EXISTS keywords. What kind of situations should I use each keyword to attain optimal performance? thanks.
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
When you have a choice of using the IN or the EXISTS clause in your Transact-SQL, you will generally want to use the EXISTS clause, as it is usually more efficient and performs faster.
[Blue]SELECT[/Blue] col1[Gray],[/Gray] col2[Gray],[/Gray] col3[Gray],[/Gray] col4
[Blue]FROM[/Blue] Table_1 T1 [Blue]INNER[/Blue] [Gray]JOIN[/Gray] Table_2 T2
[Blue]ON[/Blue] [Gray]([/Gray]T1.col1[Gray]=[/Gray]T2.col1[Gray])[/Gray]
[Blue]SELECT[/Blue] col1[Gray],[/Gray] col2[Gray],[/Gray] col3[Gray],[/Gray] col4
[Blue]FROM[/Blue] Table_1 T1 [Blue]WHERE[/Blue] exists
[Gray]([/Gray][Blue]SELECT[/Blue] col1 [Blue]FROM[/Blue] Table_2 T2
[Blue]WHERE[/Blue] T1.col1[Gray]=[/Gray]T2.col1[Gray])[/Gray]