IN Operator in SQL
The IN operator in SQL is used to filter records based on a specified list of values. It is often used in the WHERE clause to specify multiple values in a condition.
SQL Syntax
SELECT column1, column2, ... FROM table_name WHERE column_name IN (value1, value2, ...);
Examples:1. Basic Usage of IN Operator Example: Find employees who work in departments with department_id: 10, 20, or 30.
SQL Syntax
SELECT employee_id, first_name, last_name, department_id FROM employees WHERE department_id IN (10, 20, 30);
Explanation: • The query selects all employees whose department_id is either 10, 20, or 30.
3. Using NOT IN Operator Example: Find employees who do not work in departments 10, 20, or 30.
SQL
SELECT employee_id, first_name, last_name, department_id FROM employees WHERE department_id NOT IN (10, 20, 30);
Explanation: • The query selects employees whose department_id is not 10, 20, or 30.