N012-H1 Tier 1 · Foundations · hard ecommerce · Brightlane

Return the name of every product that qualifies

Part of BETWEEN, IN, and LIKE in SQL

The problem

Brightlane's discount programme applies to standard Apex Titan models only. A qualifying model has a name that starts with Apex Titan 1 and is followed by exactly one additional character — not zero, not two.

Write a query to return the name of every product that qualifies.

Assumptions:

  • The products table contains every product in Brightlane's catalogue.
  • The catalogue contains names like Apex Titan 1, Apex Titan 13, Apex Titan 15, and Apex Titan 15 Pro — only the ones with exactly one trailing character (e.g., Apex Titan 13) qualify.

Output:

  • One row per qualifying product, with a single column name.
Schema · ecommerce 5 tables
categories
id integer
name text
parent_id? integer
products
id integer
name text
category_id integer
price numeric
stock_qty integer
attributes? jsonb
order_items
id integer
order_id integer
product_id integer
quantity integer
unit_price numeric
customers
id integer
name text
email text
city? text
country text
created_at timestamptz
is_active boolean
orders
id integer
customer_id integer
ordered_at timestamptz
status text
total_amount numeric

Run previews · Check grades

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

Worked solution Try it yourself first
Solution query
SELECT
  name
FROM
  products
WHERE
  name LIKE 'Apex Titan 1_'

The shape

The trailing _ is the load-bearing piece. LIKE 'Apex Titan 1_' matches the literal prefix Apex Titan 1 followed by exactly one additional character — not zero, not two — which is what the discount programme's eligibility rule needs.

Clause by clause

  • SELECT name returns the single column the eligibility report needs: the product label, so the team can see which Apex Titan models qualify.
  • FROM products reads the catalogue.
  • WHERE name LIKE 'Apex Titan 1_' keeps only the rows whose name matches the pattern character-for-character: the literal Apex Titan 1, then any single character. Apex Titan 15 matches because 5 fills the _ slot. Apex Titan 1 is rejected because there's nothing after the 1 and _ requires exactly one character. Apex Titan 15 Pro is rejected because the _ only accepts one character and the name continues for several more after the 5.

Why this and not LIKE 'Apex Titan 1%'

The two wildcards encode different rules. _ matches exactly one character; % matches zero or more. They're not interchangeable — they answer different questions.

LIKE 'Apex Titan 1%' would let Apex Titan 1, Apex Titan 13, Apex Titan 15, and Apex Titan 15 Pro all through. The % absorbs whatever comes after the 1, including nothing at all. That's the wrong filter for the discount programme, which is restricted to standard models — a name with a Pro suffix or no trailing digit shouldn't qualify.

The choice between _ and % is precision versus open-ended length. Use _ when the count of remaining characters is fixed and known. Use % when the tail can be any length, including empty.

The trap

Reach for % by default and the eligibility rule gets quietly widened. The query runs, returns a plausible-looking list, and the discount applies to models that were never supposed to qualify. The fix is to read the rule literally: "exactly one additional character" is _, full stop. The same reasoning extends to multi-character fixed-length matches — '__' for two characters, '___' for three. Each underscore is one character, no more and no less.

You practiced matching exactly one character with the _ wildcard. The recurring choice between _ and % is precision vs. open-ended length.

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.

Practice, feedback, mastery, review. That's the loop that turns reading into real skill.

Start free

No account, no credit card. Start solving in under a minute.