IN and BETWEEN Operators – SQL Tutorial for Beginners

11/22/2025
All Articles

SQL IN and BETWEEN operators tutorial with examples

IN and BETWEEN Operators – SQL Tutorial for Beginners

IN and BETWEEN Operators – SQL Tutorial for Beginners

The IN and BETWEEN operators in SQL help you filter data efficiently based on multiple values or a specific range. These operators make your queries cleaner, faster, and easier to understand.

In this SQL tutorial, you will learn:

  • What IN operator is

  • What BETWEEN operator is

  • Syntax and usage

  • Real-world examples

  • Best practices


🔹 What Is the IN Operator?

The IN operator allows you to filter data by matching a value against multiple possible values.

✔ Use Case

Instead of writing:

WHERE city = 'Delhi' OR city = 'Mumbai' OR city = 'Pune'

You can simply use:

WHERE city IN ('Delhi', 'Mumbai', 'Pune')

🔸 Syntax

SELECT column1, column2
FROM table_name
WHERE column_name IN (value1, value2, value3);

🔸 IN Operator Examples

Example 1: Filter employees from specific cities

SELECT * FROM employees
WHERE city IN ('Delhi', 'Mumbai', 'Bengaluru');

Example 2: Filter products by category

SELECT * FROM products
WHERE category IN ('Electronics', 'Mobile', 'Laptop');

Example 3: Exclude values using NOT IN

SELECT * FROM users
WHERE id NOT IN (1, 3, 7);

🔹 What Is the BETWEEN Operator?

The BETWEEN operator is used to filter data within a range of values.

✔ Works With

  • Numbers

  • Dates

  • Text (alphabetical range)

🔸 Syntax

SELECT column1, column2
FROM table_name
WHERE column_name BETWEEN value1 AND value2;

🔸 BETWEEN Operator Examples

Example 1: Salary range

SELECT * FROM employees
WHERE salary BETWEEN 30000 AND 60000;

Example 2: Date range

SELECT * FROM orders
WHERE order_date BETWEEN '2024-01-01' AND '2024-03-31';

Example 3: Text range

SELECT * FROM students
WHERE name BETWEEN 'A' AND 'M';

Example 4: NOT BETWEEN

SELECT * FROM sales
WHERE amount NOT BETWEEN 500 AND 1000;

🔹 Combining IN and BETWEEN

You can use both operators together.

Example: Products in category + price range

SELECT * FROM products
WHERE category IN ('Mobile', 'Laptop')
AND price BETWEEN 20000 AND 50000;

🔹 Real-World Use Cases

✔ Filtering Users Between Age Groups

SELECT * FROM users
WHERE age BETWEEN 18 AND 30;

✔ Finding Orders From Specific Statuses

SELECT * FROM orders
WHERE status IN ('Pending', 'Shipped');

✔ Sales Report for a Quarter

SELECT * FROM sales
WHERE sale_date BETWEEN '2024-04-01' AND '2024-06-30';

🔹 Best Practices

✔ Use IN for matching multiple fixed values
✔ Use BETWEEN for numeric/date ranges
✔ Always verify date formats (YYYY-MM-DD)
✔ Use parentheses when combining with AND/OR
✔ Avoid NOT IN with NULL values (use NOT EXISTS instead)


Summary

In this tutorial, you learned:

  • How to use the IN operator to match multiple values

  • How to use the BETWEEN operator to filter ranges

  • Real-world examples for both operators

  • Best practices for writing clean SQL queries

IN and BETWEEN make SQL filtering simpler, faster, and more readable.

Article