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
productstable contains every product in Brightlane's catalogue. - The catalogue contains names like
Apex Titan 1,Apex Titan 13,Apex Titan 15, andApex 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
Run previews · Check grades
Write a query, then run it to see results here.
Worked solution Try it yourself first
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 namereturns the single column the eligibility report needs: the product label, so the team can see which Apex Titan models qualify.FROM productsreads the catalogue.WHERE name LIKE 'Apex Titan 1_'keeps only the rows whosenamematches the pattern character-for-character: the literalApex Titan 1, then any single character.Apex Titan 15matches because5fills the_slot.Apex Titan 1is rejected because there's nothing after the1and_requires exactly one character.Apex Titan 15 Prois rejected because the_only accepts one character and the name continues for several more after the5.
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.