IN
Operator – Check Multiple Values EasilyThe IN
operator allows you to specify multiple values in a WHERE
clause. It is a shorthand for multiple OR
conditions and makes queries cleaner and easier to read.
SELECT column_name(s) FROM table_name WHERE column_name IN (value1, value2, value3, ...);
1. Select employees who work in departments 1, 3, or 5:
SELECT * FROM employees WHERE department_id IN (1, 3, 5);
Explanation: Returns rows where department_id
is 1, 3, or 5.
2. Select products that are in specific categories:
SELECT * FROM products WHERE category IN ('Books', 'Electronics', 'Clothing');
Explanation: Returns products whose category matches any of the listed values.
3. Select customers from a list of specific cities:
SELECT * FROM customers WHERE city IN ('Mumbai', 'Delhi', 'Bangalore');
Explanation: Returns customers located in Mumbai, Delhi, or Bangalore.
NOT IN
You can use NOT IN
to exclude multiple values:
SELECT * FROM employees WHERE department_id NOT IN (2, 4);
Explanation: Selects employees who are NOT in department 2 or 4.
Find orders where the status is either 'Pending', 'Processing', or 'On Hold'.
SELECT * FROM orders WHERE status IN ('Pending', 'Processing', 'On Hold');
IN
checks if a value exists in a list of values.OR
conditions.NOT IN
excludes listed values.Help others discover Technorank Learning by sharing your honest experience.
Your support inspires us to keep building!