IN
Test whether a value is one of a list. Shorter than several OR conditions.
Syntax
column IN (value1, value2, …);
- column NOT IN (…) keeps the rows whose value is not in the list.
Example
SELECT order_id FROM orders WHERE customer_id IN (1, 3, 5);
Orders placed by customers 1, 3 or 5.
Tables used: orders. Try it in a lesson below.
Common mistakes
- If the list contains NULL, NOT IN returns no rows. Filter the NULLs out of the list first.