Introduction
IN and NOT IN help you find rows where a value matches or does not match any value in a list. They make checking multiple values easy and quick.
SELECT column_name(s) FROM table_name WHERE column_name IN (value1, value2, ...); SELECT column_name(s) FROM table_name WHERE column_name NOT IN (value1, value2, ...);
SELECT * FROM employees WHERE department IN ('Sales', 'Marketing');
SELECT * FROM products WHERE category NOT IN ('Electronics', 'Toys');
SELECT name FROM students WHERE grade IN ('A', 'B', 'C');
CREATE TABLE employees ( id INT, name VARCHAR(50), department VARCHAR(50) ); INSERT INTO employees VALUES (1, 'Alice', 'Sales'), (2, 'Bob', 'HR'), (3, 'Charlie', 'Marketing'), (4, 'Diana', 'IT'); SELECT name FROM employees WHERE department IN ('Sales', 'Marketing'); SELECT name FROM employees WHERE department NOT IN ('Sales', 'Marketing');
IN operator do in a MySQL query?status is either 'active', 'pending', or 'closed'?IN followed by parentheses containing a comma-separated list of values.employees with a column department, what will this query return?SELECT name FROM employees WHERE department NOT IN ('HR', 'Finance');SELECT * FROM orders WHERE order_status NOT IN 'shipped', 'delivered';
NOT IN to achieve this?Pass the test and this pattern moves unknown