IN is a comparison operator that returns TRUE when the expression on its left equals at least one element in a parenthesized list of literals or the single-column result of a subquery. It is semantically identical to a series of OR-combined equality checks but is more concise and often clearer. When the list contains NULL, the operator ignores it because equality to NULL is unknown. The right-hand list must contain comparable data types, otherwise implicit casting rules apply and may change query plans. Modern optimizers can rewrite IN predicates into hash or semi-join operations for performance. NOT IN is the logical negation and behaves differently with NULLs: if any element in the list is NULL, NOT IN returns UNKNOWN for all rows, effectively filtering nothing unless handled with IS NOT NULL or COALESCE.
value_list
(list) - Comma separated literals or expressionssubquery
(query) - A subquery that returns one columnexpression
(expression) - The value being testedNOT IN, EXISTS, ANY/SOME, JOIN, WHERE, CASE, NULL handling
SQL-92
IN materializes the right-hand list then compares equality, while EXISTS stops at the first matching row and can be correlated. Performance depends on data size and indexing.
Yes. All literals in the list must be comparable to the tested expression’s data type.
Most engines support thousands of literals, but very large lists can bloat the query plan. Consider temporary tables or JOINs for huge sets.
No. IN is a membership test, not an ordering clause. Use ORDER BY to sort the final result.