EVIKA.ACADEMY›SQL Tutorial
SQL Tutorial›IN & BETWEEN

SQL IN and BETWEEN

Chapter 18 of 40 · Estimated read time: 7 min

IN checks whether a value matches any item in a list. BETWEEN checks whether a value falls within a range. Both are shorthand for chained OR conditions — cleaner to write and easier to read.

The IN Operator

WHERE column IN (value1, value2, value3, ...) -- Equivalent to: WHERE column = value1 OR column = value2 OR column = value3

Example 1 — Products in Specific Categories

SELECT product_name, category, price
FROM products
WHERE category IN ('Electronics', 'Furniture')
ORDER BY category, price;
product_namecategoryprice
HDMI CableElectronics299
Wireless MouseElectronics899
USB-C HubElectronics1499
Desk LampFurniture1199
Ergonomic ChairFurniture8999
IN ('Electronics', 'Furniture') is identical to = 'Electronics' OR category = 'Furniture' — just shorter and easier to extend.

Example 2 — Specific Customers by ID

SELECT customer_name, city
FROM customers
WHERE customer_id IN ('C01', 'C03', 'C05');
customer_namecity
Amit VermaNoida
Rohan MehtaMumbai
Arjun SinghBengaluru

NOT IN — Exclude a List

-- All products that are NOT Electronics
SELECT product_name, category
FROM products
WHERE category NOT IN ('Electronics');
product_namecategory
Notebook A5Stationery
Ballpoint PensStationery
Desk LampFurniture
Ergonomic ChairFurniture
Watch out: NOT IN with NULLs. If the list contains a NULL value, NOT IN returns no rows at all — because value != NULL is UNKNOWN in SQL. Always ensure your list has no NULLs when using NOT IN, or use NOT EXISTS instead.

IN with a Subquery

-- Customers who have placed at least one order
SELECT customer_name, city
FROM customers
WHERE customer_id IN (
  SELECT DISTINCT customer_id FROM orders
);
All 5 customers have orders in our dataset
customer_namecity
Amit VermaNoida
Priya SharmaDelhi
Rohan MehtaMumbai
Sneha GuptaNoida
Arjun SinghBengaluru

The BETWEEN Operator

WHERE column BETWEEN low_value AND high_value -- Equivalent to: WHERE column >= low_value AND column <= high_value
BETWEEN is inclusive on both ends. BETWEEN 500 AND 1500 includes rows where the value is exactly 500 or exactly 1500.

Example 3 — Products in a Price Range

SELECT product_name, price
FROM products
WHERE price BETWEEN 500 AND 1500
ORDER BY price;
Includes 500 and 1500 (both boundaries inclusive)
product_nameprice
Wireless Mouse899
Desk Lamp1199
USB-C Hub1499

Example 4 — Orders in a Date Range

-- Orders placed between Oct 3 and Oct 6 (inclusive)
SELECT order_id, customer_id, order_date, total_amount
FROM orders
WHERE order_date BETWEEN '2026-10-03' AND '2026-10-06'
ORDER BY order_date;
order_idcustomer_idorder_datetotal_amount
1003C012026-10-03495
1004C032026-10-048999
1005C042026-10-052398
1006C052026-10-06299

NOT BETWEEN — Exclude a Range

-- Products priced outside the ₹100–₹1000 range
SELECT product_name, price
FROM products
WHERE price NOT BETWEEN 100 AND 1000
ORDER BY price;
product_nameprice
Ballpoint Pens49
Notebook A599
Desk Lamp1199
USB-C Hub1499
Ergonomic Chair8999
✏️ Practice Exercises
1. Find all customers from Noida or Delhi using IN.
2. Find products priced between ₹200 and ₹900 (inclusive).
3. Find orders placed on October 1st, 2nd, or 8th using IN on order_date.
Show Answers
-- 1.
SELECT customer_name, city FROM customers
WHERE city IN ('Noida', 'Delhi');

-- 2.
SELECT product_name, price FROM products
WHERE price BETWEEN 200 AND 900
ORDER BY price;

-- 3.
SELECT order_id, order_date, total_amount FROM orders
WHERE order_date IN ('2026-10-01', '2026-10-02', '2026-10-08');