IN and BETWEEN Operators

SQL FundamentalsDMLFree Lesson

Advertisement

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

  1. IN checks if a value is in a list of values
  2. BETWEEN checks if a value is in a range (inclusive)
  3. Both work with numbers, text, and dates
  4. Use NOT IN and NOT BETWEEN to negate
  5. IN is cleaner than multiple OR conditions

Advertisement

Need Expert SQL Help?

Get personalized SQL training or database consulting.

Advertisement