IN, BETWEEN, and LIKE

Basic SQL
≈ 1 min read

IN checks a set of values

IN is convenient when one value needs to be compared with several allowed options.

SELECT name
FROM products
WHERE category IN ('book', 'course', 'video');

This is shorter and clearer than repeating several comparisons with OR.

BETWEEN checks a range

SELECT name, price
FROM products
WHERE price BETWEEN 1000 AND 3000;

BETWEEN includes both ends of the range. In the example, both 1000 and 3000 are included.

LIKE matches a pattern

SELECT name
FROM users
WHERE name LIKE 'Ann%';

In a pattern, % means a sequence of zero or more characters. So the condition matches strings that start with Ann.

Another common pattern character is _: it matches exactly one character.

Case sensitivity for LIKE depends on the database system and string comparison settings. Do not automatically assume that LIKE is case-insensitive. Its behavior must be understood in the context of the specific database.