MySQL IN Operator (original) (raw)

Last Updated : 25 Mar, 2026

The IN operator is used to filter data by matching a column’s value against a specified set of values. It is commonly used in SQL queries to simplify multiple conditions.

**Syntax:

SELECT column1, column2, ... FROM table_name WHERE column_name IN (value1, value2, ...);

Working with the MySQL IN Operator

The MySQL IN operator is used in practical examples to show how multiple values can be matched in a query. It helps in filtering data efficiently by checking a column against a list of values. First, we will create a demo table on which the IN operator will be applied:

Screenshot-2026-03-25-145123

studentsInfo Table

Example 1: Select students who are in grades 'A' or 'B'

This example retrieves students whose grades match either 'A' or 'B' using the IN operator.

**Query:

SELECT id, name, grade, city FROM studentsInfo WHERE grade IN ('A', 'B');

**Output:

Screenshot-2026-03-25-150552

Example 2: Select students whose city is not Los Angeles or Phoenix

This example finds students whose cities do not match the specified values using the NOT IN operator.

**Query:

SELECT id, name, city FROM studentsInfo WHERE city NOT IN ('Los Angeles', 'Phoenix');

**Output:

Screenshot-2026-03-25-150458

Example 3: Select students aged 18, 20, or 22

This example filters students whose ages match any value in the given list.

**Query:

SELECT id, name, age, city FROM studentsInfo WHERE age IN (18, 20, 22);

**Output:

Screenshot-2026-03-25-150331