Titles Ending With S

An easy SQL interview practice problem on DataDriven. Write the query and run it against a real database, with instant feedback.

Domain
SQL
Difficulty
easy
Seniority
L3
Asked in
Amazon

Problem

Pull all content items whose title ends with the letter 's', listed alphabetically by title so the catalog reads in order. For each item show the content ID, title, content type, duration in seconds, creator ID, and publish date, and when two share a title put the lower content ID first.

Naming conventions. Specifically the plurals.

Tables

content_items

Columns: content_id INTEGER, title TEXT, content_type TEXT, duration_seconds INTEGER, creator_id INTEGER, publish_date TEXT

content_items: 10 of 200 rows
content_idtitlecontent_typeduration_secondscreator_idpublish_date
243The Ultimate Guide to AI TrendsarticleNULL1972026-02-02
286Top 10 Mobile Appspodcast1542942025-03-03
329Understanding Machine Learning [DRAFT]short2013912026-04-04
372Mastering Tech Startupslivestream2484882025-05-05
415Introduction to Cybersecurityvideo2955852026-06-06
458Deep Dive: Cloud ComputingarticleNULL6822025-07-07
501Behind the Scenes of Product Managementpodcast3897792026-08-08
544Breaking Down DevOpsshort4368762025-09-09
587Exploring Web Developmentlivestream483NULL2026-01-10
630How to Data Sciencevideo53010702025-11-11

Expected output

First 5 of 80 rows
content_idtitlecontent_typeduration_secondscreator_idpublish_date
544Breaking Down DevOpsshort4368762025-09-09
974Breaking Down DevOpsshort906NULL2025-07-19
372Mastering Tech Startupslivestream2484882025-05-05
243The Ultimate Guide to AI TrendsarticleNULL1972026-02-02
286Top 10 Mobile Appspodcast1542942025-03-03

Worked solution and explanation

What this really tests

This is a suffix match dressed up as a catalog pull. Everyone reaches for LIKE; what separates candidates is where the wildcard goes. '%s%' asks whether an 's' appears anywhere, and on content_items that drags in 'Introduction to Cybersecurity' and 'Behind the Scenes of Product Management', so the 80-row answer quietly swells and still looks plausible. The second signal is what you ask before typing: is the match case-sensitive, and are the titles trimmed?


Break down the requirements

Step 1: Pick the suffix predicate

Filter content_items.title with LIKE '%s'. The leading % says any prefix, the literal s pins the final character.

Step 2: Nail case sensitivity

SQLite's LIKE is ASCII case-insensitive by default; Postgres LIKE is case-sensitive. Ask the interviewer which engine. Portable form: title LIKE '%s' OR title LIKE '%S', or normalize with LOWER(title) LIKE '%s'.

Step 3: Defend against trailing whitespace

'Articles ' LIKE '%s' is false because the last character is a space. If content_items.title is dirty, wrap in TRIM(title) LIKE '%s'. State the assumption either way.

Step 4: Project the asked columns and sort

Name content_id, title, content_type, duration_seconds, creator_id, publish_date explicitly rather than SELECT *. Then ORDER BY title, content_id: the catalog reads A to Z, and repeated titles such as 'Breaking Down DevOps' list the lower content_id first.


The solution

SUFFIX FILTER
SELECT content_id,
       title,
       content_type,
       duration_seconds,
       creator_id,
       publish_date
FROM content_items
WHERE title LIKE '%s'
ORDER BY title, content_id;

COMMON FOLLOW-UP QUESTIONS

Common follow-up questions