How to Use IN in SQL

Use IN when a column should match one of several exact values. This is much cleaner than chaining multiple OR conditions and works especially well for filters, role checks, and grouped reporting.

What you’ll build or solve

You’ll learn how to use IN in SQL with exact-match lists and subqueries. You’ll also know when it reads better than repeated OR logic.

When this approach works best

This approach is the right choice when one column can match several known values.

Common real-world scenarios include:

  • Multiple order statuses
  • Selected user roles
  • Country filters
  • Product category sets
  • ID list lookups

This is a bad idea when the condition is range-based. In that case, use comparison operators or BETWEEN.

Prerequisites

You only need:

  • A SQL table with rows
  • Basic SELECT and WHERE knowledge

Step-by-step instructions

Step 1: Add IN with a list of exact values

Place IN after the target column.

SELECT *
FROM orders
WHERE status IN ('paid', 'pending', 'refunded');

This returns rows where status matches any listed value.

This is cleaner than repeating:

WHERE status = 'paid'
OR status = 'pending'
OR status = 'refunded'

IN also works with numeric IDs.

SELECT *
FROM users
WHERE user_id IN (5, 9, 12);

What to look for:

  • IN checks multiple exact values
  • Cleaner than repeated OR
  • Works with strings and numbers
  • Great for grouped filters
  • Use subqueries for dynamic lists

Examples you can copy

Multiple roles

SELECT *
FROM users
WHERE role IN ('admin', 'editor');

Selected products

SELECT *
FROM products
WHERE product_id IN (101, 102, 103);

Country filter

SELECT *
FROM customers
WHERE country IN ('USA', 'UK', 'France');

Common mistakes and how to fix them

Mistake 1: Forgetting parentheses

What the reader might do:

WHERE status IN 'paid', 'pending'

Why it breaks: IN requires parentheses around the list.

Corrected approach:

WHERE status IN ('paid', 'pending')

Mistake 2: Mixing data types

What the reader might do:

WHERE user_id IN ('5', '9')

Why it breaks: string IDs may behave differently on numeric columns.

Corrected approach:

WHERE user_id IN (5, 9)

Mistake 3: Using IN for ranges

What the reader might do:

WHERE total IN (100, 200, 300)

Why it breaks: this checks only exact totals.

Corrected approach:

Use range operators.

WHERE total BETWEEN 100 AND 300

Troubleshooting

If nothing matches, verify the exact values and data types.

If the syntax errors, check the parentheses.

If the list becomes dynamic, switch to a subquery.

If the filter is a numeric range, use BETWEEN or comparison operators.

Quick recap

  • Use IN for multiple exact values
  • Cleaner than repeated OR
  • Always wrap values in parentheses
  • Match data types correctly
  • Use ranges for numeric spans