Lesson 15 +10 XP

IN Operator

IN Operator

The IN operator lets you match a column against a list of values. It is a short way of writing several OR conditions.

Basic example

SELECT * FROM Customers
WHERE Country IN ('Germany', 'France', 'UK');

Same as:

SELECT * FROM Customers
WHERE Country = 'Germany' OR Country = 'France' OR Country = 'UK';

IN with numbers

SELECT * FROM Products
WHERE Price IN (10, 20, 30);

NOT IN

SELECT * FROM Customers
WHERE Country NOT IN ('Germany', 'France');

Excludes Germany and France.

IN with a subquery

SELECT * FROM Customers
WHERE CustomerID IN (SELECT CustomerID FROM Orders);

Returns customers who have at least one order.

When to use it

Use IN when you have a fixed list of values. It reads cleaner than a long chain of OR conditions.

TL;DR

  • IN matches one of several values.
  • It is shorthand for multiple OR conditions.
  • NOT IN excludes those values.
  • The list can also come from a subquery.