Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mysql NOT IN and NOT EXIST the same?

Tags:

mysql

I sometimes interchanged the use of NOT IN and NOT EXIST in my sql queries and both yield the same result. Is the logic behind the NOT EXIST the same as NOT IN? Because I think that NOT IN... (is being evaluated as "OR" inside the subqueries) is equal to NOT EXIST (which is also evaluated as "OR")? Or am i missing something?

like image 648
newbie Avatar asked Apr 25 '11 15:04

newbie


1 Answers

This article may be of interest to you:

  • NOT IN vs. NOT EXISTS vs. LEFT JOIN / IS NULL: MySQL

In a nutshell, NOT IN is slightly different from NOT EXISTS in the way the two handle NULL values returned by the subquery.

If there are no NULL values, they both perform a kind on NESTED LOOP ANTI JOIN, but NOT IN is a little bit more efficient.

like image 157
Quassnoi Avatar answered Nov 08 '22 20:11

Quassnoi