Exist in the SQL server and the difference

 

Exists: Each row of the outer table query, the query is substituted as a test, if the result of the query returns a non-null value is taken, the EXISTS clause returns TRUE, the result of this query trekking as outer rows, or can not, as a result.

 

the difference:

IN the outer and the inner table is a hash table is connected, it is to execute sub-queries.
EXISTS is the appearance of circulation, including tables and queries.

 

Scope:
when the query is indexed field, the primary table from Table A is greater than B, the use of higher efficiency IN subqueries, A is smaller than the opposite primary table from Table B, the use of higher efficiency EXISTS subqueries 


IN has a defect determination is not NULL, NULL value field is present if so, return occurs, is preferably used because NOT EXISTS.

 

Here is the execution plan of SQL Server:

 

 

 

Guess you like

Origin www.cnblogs.com/amusement1992/p/11269496.html