Content Types by Creator
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
- ESPN
Problem
Each row of content_items is one published piece tagged with its content_type and its creator_id, and a creator who publishes often appears on many rows. Across the creators whose creator_id is below 300, list the content types they have published, each type once.
One creator. What did they make?
Tables
content_items
Columns: content_id INTEGER, title TEXT, content_type TEXT, duration_seconds INTEGER, creator_id INTEGER, publish_date TEXT
| content_id | title | content_type | duration_seconds | creator_id | publish_date |
|---|---|---|---|---|---|
| 243 | The Ultimate Guide to AI Trends | article | NULL | 197 | 2026-02-02 |
| 286 | Top 10 Mobile Apps | podcast | 154 | 294 | 2025-03-03 |
| 329 | Understanding Machine Learning [DRAFT] | short | 201 | 391 | 2026-04-04 |
| 372 | Mastering Tech Startups | livestream | 248 | 488 | 2025-05-05 |
| 415 | Introduction to Cybersecurity | video | 295 | 585 | 2026-06-06 |
| 458 | Deep Dive: Cloud Computing | article | NULL | 682 | 2025-07-07 |
| 501 | Behind the Scenes of Product Management | podcast | 389 | 779 | 2026-08-08 |
| 544 | Breaking Down DevOps | short | 436 | 876 | 2025-09-09 |
| 587 | Exploring Web Development | livestream | 483 | NULL | 2026-01-10 |
| 630 | How to Data Science | video | 530 | 1070 | 2025-11-11 |
Expected output
| content_type |
|---|
| article |
| podcast |
| video |
Worked solution and explanation
What this really is
This is a dedupe question in an editorial costume. Everyone writes the filter correctly. The trap is believing that narrowing to a handful of creators also narrows the output to a handful of rows. It does not: content_items holds one row per piece, so each of those creators shows up several times. A bare projection of content_type returns 12 rows when the answer is three, with 'video' repeated 4 times, and the reviewer reading it believes the creators published far more kinds of content than they did.
Getting there
Step 1: Keep only the creators in scope
WHERE creator_id < 300 keeps the low-numbered creators. Rows with a missing creator_id drop out on their own, since a comparison against NULL is never true, so no extra guard is needed.
Step 2: Collapse the repeats
The question is about which types exist, not how many pieces carry them. SELECT DISTINCT content_type turns every pile of identical rows into one, which is exactly the list the reviewer asked for.
SELECT DISTINCT content_type
FROM content_items
WHERE creator_id < 300- Without dedupe
SELECT content_type ... WHERE creator_id < 300returns one row per item: 12 rows, each type repeated once per piece the creator published.- With dedupe
SELECT DISTINCT content_typereturns 'video', 'article' and 'podcast', one row each: the actual answer.
Common follow-up questions
- How would you show how many pieces each type has for these creators? (Switch to `GROUP BY content_type` with `COUNT(*)`; the dedupe now carries an aggregate.)
- Which creators in scope have published more than one type? (Group by `creator_id` and keep groups where `COUNT(DISTINCT content_type) > 1`.)
- What if `content_type` were entered by hand, with 'Video' and 'video ' both present? (Tests normalizing with `LOWER(TRIM(content_type))` before deduping, or one type counts twice.)