IN in MySQL — How It Works
What the MySQL IN function does, with an example.
Published October 22, 2026
IN (list or subquery) tests whether a value matches any value in a list. It is shorthand for several OR conditions.
How it works
NOT IN returns no rows if the list contains NULL.
Try it in MySQL
SELECT * FROM users WHERE id IN (1, 2, 3)
three users
SELECT * FROM users WHERE id IN (SELECT user_id FROM orders)
buyers
SELECT * FROM t WHERE status NOT IN ('a', 'b')
others
Practical examples
Example 1
SELECT * FROM users WHERE id IN (1, 2, 3);
-- three usersExample 2
SELECT * FROM users WHERE id IN (SELECT user_id FROM orders);
-- buyersExample 3
SELECT * FROM t WHERE status NOT IN ('a', 'b');
-- othersUse it in a real query
SELECT * FROM users WHERE id IN (1, 2, 3);Common mistakes
- NOT IN with NULLs returning nothing.
- Huge IN lists (use a join or temporary table).
- Case/collation differences.
Key takeaways
- IN in one line: IN (list or subquery) tests whether a value matches any value in a list.
- Try queries in a test database first.
- Check NULL handling and data types.
FAQ
NOT IN with NULL?
If the list has a NULL, the comparison is unknown and no rows match; use NOT EXISTS.
Does IN work in other databases?
Most have an equivalent, but names and syntax vary between MySQL, PostgreSQL, SQL Server and SQLite.