IN and BETWEEN Operators
IN checks if a value matches any value in a list. BETWEEN checks if a value is within a range.
IN Operator
SELECT * FROM employees
WHERE department IN ('Engineering', 'Sales');
IN with Subquery
SELECT first_name, last_name
FROM customers
WHERE id IN (SELECT DISTINCT customer_id FROM orders);
NOT IN
SELECT * FROM employees
WHERE department NOT IN ('Engineering', 'Sales');
BETWEEN Operator
SELECT first_name, last_name, salary
FROM employees
WHERE salary BETWEEN 60000 AND 80000;
BETWEEN is inclusive — it includes both the start and end values.
BETWEEN with Dates
SELECT * FROM orders
WHERE order_date BETWEEN '2024-01-01' AND '2024-03-31';
✅ Key Takeaways
- IN checks if a value is in a list of values
- BETWEEN checks if a value is in a range (inclusive)
- Both work with numbers, text, and dates
- Use NOT IN and NOT BETWEEN to negate
- IN is cleaner than multiple OR conditions