SQL IN operator
True when the value matches any member of the list or subquery.
- Catégorie
- Conditionnel
- Returns
boolean- In this category
- 16 of 43
Syntaxe
x IN (1, 2, 3) | x IN (SELECT ...)
Prise en charge des moteurs
| Moteur | Support | Notes |
|---|---|---|
| SQL Server | Oui | Supported under this name. |
| PostgreSQL | Oui | Supported under this name. |
| MySQL | Oui | Supported under this name. |
| SQLite | Oui | Supported under this name. |
| Oracle | Oui | Supported under this name. |
Exemples
Any engine
SELECT id, status FROM orders WHERE status IN ('new', 'paid');
PostgreSQL
SELECT * FROM orders WHERE customer_id IN (SELECT id FROM vip_customers);
Bon à savoir
- x IN ('a', NULL) matches 'a' rows only; the NULL member makes the remaining comparisons UNKNOWN, never true.
- NOT IN with a single NULL in the subquery returns zero rows: the most famous NULL trap in SQL.
- For subqueries, IN is a semi-join; correlated cases often read and plan better as EXISTS.
- Long literal lists hit engine limits: 1000 expressions in Oracle, 2100 parameters in SQL Server.
Questions about IN
Why does IN ignore NULL members?
x IN (a, NULL) is x = a OR x = NULL; if the first is false the second is UNKNOWN, and WHERE keeps only TRUE.
IN vs EXISTS for subqueries?
For uncorrelated subqueries the planner usually makes them identical; for correlated checks, EXISTS states the intent and short-circuits.
How big can an IN list be?
Oracle caps at 1000 expressions (ORA-01795); SQL Server at 2100 parameters; prefer a temp table or = ANY(array) at that size.
Browse every function in the SQL function reference, or see what the SQLly desktop app does for your database.
Related on SQLly
Cheat sheets for the engines that have it: SQL Server, PostgreSQL, MySQL, SQLite, Oracle.
Functions your engine actually has
SQLly's completion lists the built-in functions of the engine you're connected to, whether that's SQL Server, PostgreSQL, MySQL, SQLite or Oracle. Hover a function for help, and signature hints show each argument as you type.