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_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 3 of 3 rows
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 twelve rows when the answer is three, with 'video' repeated four 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.

Each type once
SELECT DISTINCT content_type
FROM content_items
WHERE creator_id < 300
Without dedupe
SELECT content_type ... WHERE creator_id < 300 returns one row per item: twelve rows, each type repeated once per piece the creator published.
With dedupe
SELECT DISTINCT content_type returns 'video', 'article' and 'podcast', one row each: the actual answer.

Common follow-up questions