In Operator in SQL
IN Operator in SQL
The IN operator is used in a WHERE clause to filter rows where a column’s value matches any value in a specified list or subquery.
Syntax:
SELECT columnsFROM table_nameWHERE column_name IN (value1, value2, value3, ...);Or with a subquery:
SELECT columnsFROM table_nameWHERE column_name IN ( SELECT column_name FROM other_table WHERE condition);Example 1: Using IN with a list of values
Find employees who belong to departments 'Sales', 'Marketing', or 'IT':
SELECT *FROM employeesWHERE department IN ('Sales', 'Marketing', 'IT');Example 2: Using IN with a subquery
Find orders placed by customers from the customers table:
SELECT *FROM ordersWHERE customer_id IN ( SELECT customer_id FROM customers WHERE country = 'USA');Notes:
INis equivalent to multipleORconditions but cleaner and easier to read.Use
NOT INto exclude specific values.Works with numbers, strings, and dates.
If you want help with complex IN queries or related concepts, just ask!