sqlcmd.net validated sql reference
beginner filtering MySQL MariaDB SQL Server PostgreSQL SQLite

Filter Rows Matching A List With IN

Use `IN` to match a column against a list of values in a single `WHERE` clause.

Docker-validated Not currently validation-green

Return only products in selected categories

The Food row (Apple) is excluded because 'Food' is not in the list. This is equivalent to WHERE category = 'Electronics' OR category = 'Clothing' but easier to read and extend.

Rows loaded before the example query runs.
Setup
CREATE TABLE products (id INT, name VARCHAR(50), category VARCHAR(50));

INSERT INTO
  products (id, name, category)
VALUES
  (1, 'Keyboard', 'Electronics'),
  (2, 'Mouse', 'Electronics'),
  (3, 'Shirt', 'Clothing'),
  (4, 'Apple', 'Food');
Shared across supported engines.
SQL
SELECT
  name,
  category
FROM
  products
WHERE
  category IN ('Electronics', 'Clothing')
ORDER BY
  id;
Returned rows for the shared example.
namecategory
KeyboardElectronics
MouseElectronics
ShirtClothing

Output is identical across all engines.

Where this command helps.

  • matching rows against a known set of values
  • replacing multiple OR conditions with a concise list check

What the command is doing.

IN (value1, value2, ...) is shorthand for multiple OR conditions on the same column. It keeps the query readable when checking against more than two values. NOT IN excludes the listed values instead. Both work with string and numeric columns.