Basic · Lesson 3 of 14

IN, LIKE, BETWEEN

Smarter conditions for real text and ranges.

IN for a list

IN checks membership in a list, a much cleaner alternative to a chain of OR conditions.

LIKE for patterns

The % wildcard matches any run of characters and _ matches exactly one. In PostgreSQL LIKE is case-sensitive; use ILIKE when you want case-insensitive matches for interview-style text data.

BETWEEN is inclusive

BETWEEN includes both endpoints. For dates, prefer the half-open form col >= '2024-01-01' AND col < '2024-02-01' to avoid silently dropping the last day.

Examples

Membership with IN

Three countries, one clean clause.

SELECT user_id, country FROM users WHERE country IN ('Nigeria', 'Japan', 'France');

Pattern with LIKE

Any name containing the letter o.

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

BETWEEN dates

January signups, both ends included.

SELECT user_id, signup_date FROM users WHERE signup_date BETWEEN '2024-01-01' AND '2024-02-01';