Tier 1 · Foundations

BETWEEN, IN, and LIKE in SQL

By Owen Middleton · Updated September 2026 · Examples run on PostgreSQL 17

What are BETWEEN, IN, and LIKE in SQL?

BETWEEN, IN, and LIKE are three WHERE operators that make common filter patterns cleaner to write.

They don't add new capabilities. You could express the same logic with the comparison operators you already know. What they add is readability. A range check with two bounds. A membership test against a list. A pattern match on a string. Each shows up constantly in analyst work, and writing them with the shorthand operators instead of long chains of OR keeps queries much easier to read.

How do you filter a range with BETWEEN in SQL?

You're filtering the product catalog for a specific price range. Your manager wants items between $50 and $200. That's BETWEEN:

SELECT name, price
FROM products
WHERE price BETWEEN 50 AND 200

Both ends of the range are included. A price of exactly $50 qualifies. A price of exactly $200 qualifies. Anything in between qualifies. BETWEEN is shorthand for >= 50 AND <= 200 — both forms produce identical results.

How do you match a list of values with IN?

IN tests whether a value matches any member of a list. Instead of chaining multiple equality conditions with OR, you write:

SELECT id, status
FROM orders
WHERE status IN ('pending', 'shipped')

Easy to extend — add another status to the list without restructuring anything. NOT IN inverts it: keep rows where the value doesn't match anything in the list.

How do the % and _ wildcards work in LIKE?

LIKE matches a string against a pattern. Two wildcards handle most pattern needs: % matches any sequence of characters (including none), and _ matches exactly one character:

SELECT name, price
FROM products
WHERE name LIKE 'Crest%'

Any product whose name starts with "Crest" passes. The _ wildcard is more precise: 'Apex Titan 1_' matches "Apex Titan 15" but not "Apex Titan 15 Pro" because _ requires exactly one character at that position.

Is LIKE case-sensitive in PostgreSQL?

The one thing that trips people up: LIKE is case-sensitive.

WHERE name LIKE 'crest%' will not match a product called "Crest Pro 14" — lowercase c doesn't match uppercase C. For case-insensitive matching, use ILIKE:

SELECT name, title
FROM employees
WHERE title ILIKE '%manager%'

ILIKE is PostgreSQL-specific. It matches regardless of case.

Check your understanding

You write WHERE name LIKE 'apex%'. The table has a product called 'Apex Titan 15'. Does this row match?

Practice BETWEEN, IN, and LIKE in SQL

Practice · easy ecommerce · Brightlane

A Brightlane buyer is reviewing the mid-range product catalogue for a quarterly selection meeting. The range of interest covers all items priced between $50 and $200, inclusive of both endpoints.

Write a query to return the name and price of every qualifying product.

Assumptions:

  • The products table contains every product in Brightlane's catalogue.
  • A product priced exactly at $50 or exactly at $200 qualifies — both endpoints are included.

Output:

  • One row per qualifying product, with columns name and price.
Schema · ecommerce5 tables? = nullable
categories
idinteger
nametext
parent_id?integer
products
idinteger
nametext
category_id?integer
pricenumeric
stock_qtyinteger
attributes?jsonb
order_items
idinteger
order_id?integer
product_id?integer
quantityinteger
unit_pricenumeric
customers
idinteger
nametext
emailtext
city?text
countrytext
created_attimestamptz
is_activeboolean
orders
idinteger
customer_id?integer
ordered_attimestamptz
statustext
total_amountnumeric

Run previews · Check grades

Write a query, then run it to see results here.

Worked solution

The full breakdown walks through the shape, each clause, why this approach beats the alternatives, and the trap to avoid.

See the full worked solution

9 BETWEEN, IN, and LIKE practice problems

Start learning to practice all 9 BETWEEN, IN, and LIKE problems, with instant grading and mastery tracking.

Common questions about BETWEEN, IN, and LIKE

Does BETWEEN include both end values?

Yes, both ends. A price between fifty and two hundred keeps a row priced at exactly fifty and one priced at exactly two hundred. It is shorthand for the two comparisons written out, and returns the same rows as writing them.

What happens if you write BETWEEN with the bounds the wrong way round?

You get no rows and no error. BETWEEN expects the smaller value first, so a range from two hundred down to fifty asks for rows that are both above two hundred and below fifty, which nothing satisfies.

Is IN the same as a chain of OR conditions?

For a list of literal values, yes, and it returns the same rows. IN is worth preferring because adding another value means adding another item to a list rather than restructuring the condition, which is where mistakes creep in.

How do you match a literal percent sign with LIKE?

Escape it, with a backslash before it or with your own escape character named in an ESCAPE clause. Left unescaped, a percent sign means any sequence of characters, so a pattern meant to find a discount label quietly matches everything instead.

How you actually get good at SQL

Reading explains SQL. Writing it, over and over with instant feedback, is what makes you fluent.

That's the whole SQLMaxx loop: 600+ real problems, instant AI feedback, mastery you can actually see, and spaced review that won't let you forget.

A stack of SQL practice problem cards, the top card showing an employees table.
615 problems · 66 concepts

Real problems. Not toy examples.

615 hand-built problems spanning all 66 concepts, from basic SELECTs to window functions, built on real schemas and real business questions, the kind you'll actually get asked on the job. Enough reps to make SQL automatic.

A retro computer showing a SQL query marked correct with a green checkmark.
Instant AI feedback

Write a query. Know if it's right in one second.

No copying an answer and hoping it clicked. The AI grader checks your real query against real data, catches exactly what's wrong, and explains the fix in plain English, like a senior analyst reading over your shoulder on every problem.

A circular mastery progress dial filling from blue to green, the SQLMaxx diamond at its center.
Mastery tracking

Stop guessing whether you actually know it.

SQLMaxx tracks every concept and shows you what you've mastered and what's still shaky. Your skills fill in one concept at a time, so 'I think I get joins' becomes something you can prove.

A SQL query editor circled by a blue return arrow with a clock, scheduled to come back for review.
Spaced review

Learn it once. Keep it for good.

Most of what you learn this week fades by next week. So when a concept comes due for review, SQLMaxx hands you a fresh problem to solve from a blank editor, not a flashcard to re-read. A research-backed spaced-repetition algorithm (FSRS) times each return for right before you'd forget, so your SQL is still there months later, when the interview or the job actually needs it.