You've already seen how to filter rows with comparison operators (=, >, <), AND/OR/NOT, BETWEEN, and LIKE. The IN operator is another WHERE-clause tool for a very common situation: checking whether a column's value matches any one of several specific values.
The problem IN solves
Suppose you want customers from India, France, or Brazil. Without IN, you'd chain OR:
SELECT * FROM customers
WHERE country = 'India' OR country = 'France' OR country = 'Brazil';
That works, but it gets repetitive fast — the column name is typed three times just to check three values. IN lets you write the same condition more compactly:
SELECT * FROM customers
WHERE country IN ('India', 'France', 'Brazil');
Both queries return exactly the same rows. IN is shorthand for "equals any of these values" — nothing more.
Syntax
WHERE column IN (value1, value2, value3, ...)
- The values go in parentheses, separated by commas.
- Strings are quoted (
'India'), numbers are not (IN (1, 2, 3)). - The list can be as short as one value or as long as you need.
NOT IN
Just like other conditions, you can negate it with NOT:
SELECT * FROM customers
WHERE country NOT IN ('India', 'France', 'Brazil');
This returns every customer except those three countries.
Combining with other conditions
IN works alongside AND/OR just like any other condition:
SELECT * FROM invoices
WHERE billing_country IN ('USA', 'Canada')
AND total > 10;
A heads-up for later
Once you get to NULL values later in this course, keep this in mind: if the list inside a NOT IN (...) could ever contain a NULL, the whole condition can unexpectedly match zero rows. You don't need to worry about this yet — just flag it as something to be careful about once NULLs are in the picture.
Recap
INchecks a column against a list of values — it's shorthand for multipleOR-chained equality checks.NOT INis the negated version — "none of these values."- Both work anywhere a normal WHERE condition works, including combined with
AND/OR.