SQL Basics
Back to DATA RETRIEVAL & FILTERING

THE IN OPERATOR

A quick-reference reading on using IN and NOT IN to match a column against a list of values.

7 minutesReading
🎯 Free Guest Mode: You are learning for free. Sign in to save your completion progress and quiz answers.

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

  • IN checks a column against a list of values — it's shorthand for multiple OR-chained equality checks.
  • NOT IN is the negated version — "none of these values."
  • Both work anywhere a normal WHERE condition works, including combined with AND/OR.
Loading progress...