IN
IN
IN
The IN
operator compares a value to a given list of values to determine if there is a match found within that list.
Syntax
The right-hand side is a parenthesized list of scalar expressions. The result is true
if the left-hand expression's result is equal to any of the right-hand expressions.
This is a shorthand notation for:
Note that if the left-hand expression yields null
, or if there are no equivalent right-hand values and at least one right-hand expression yields null
, the result of the IN
construct is null
, not false
. This is in accordance with SQL's normal rules for Boolean combinations of null values.
Examples
SQL
Query result
customer_email |
---|
Johnny.Jimeneze8@gmail.com |
Larry.Torres@yahoo.com |
Juan.Mendozaga@yahoo.com |
NOT IN
NOT IN
The right-hand side is a parenthesized list of scalar expressions. The result is true
if the left-hand expression's result is unequal to all of the right-hand expressions.
This is a shorthand notation for:
Note that if the left-hand expression yields null
, or if there are no equal right-hand values and at least one right-hand expression yields null
, the result of the NOT IN
construct will be null
, not true
. This is in accordance with SQL's normal rules for Boolean combinations of null values.
Note that x NOT IN y
is equivalent to NOT (x IN y)
in all cases.
However, users tend to make more mistakes with null values when working with NOT IN
than when working with IN
. As such, it is best to express your condition positively if possible.
Examples
SQL
Query result
customer_email |
---|
Martha.Ortizv@verizon.net |
Paul.Moore@gmx.com |
Elijah.Myersqc@aol.com |
Last updated