Geek Slack

My SQL Tutorial
About Lesson


MySQL IN Operator


MySQL IN Operator

The IN operator in MySQL allows you to specify multiple values in a WHERE clause. It is useful when you want to retrieve rows that match any of the specified values.

Example:

SELECT * FROM products WHERE category IN ('Electronics', 'Clothing', 'Furniture');

This query will retrieve all products whose category is either ‘Electronics’, ‘Clothing’, or ‘Furniture’.

Using Subquery with IN Operator:

The IN operator can also be used with a subquery to retrieve values from a subquery result.

SELECT * FROM products WHERE price IN (SELECT MAX(price) FROM products);

This query will retrieve products with the maximum price from the “products” table.

The IN operator provides a concise way to filter rows based on multiple values in MySQL queries.

Join the conversation