Content Published in 2026
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
Problem
content_items holds one row per piece of content, each stamped with the day it was published, going back several years. Return the full record of every piece published at any point in 2026.
Published back then. Still relevant?
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_id | title | content_type | duration_seconds | creator_id | publish_date |
|---|---|---|---|---|---|
| 243 | The Ultimate Guide to AI Trends | article | NULL | 197 | 2026-02-02 |
| 329 | Understanding Machine Learning [DRAFT] | short | 201 | 391 | 2026-04-04 |
| 415 | Introduction to Cybersecurity | video | 295 | 585 | 2026-06-06 |
| 501 | Behind the Scenes of Product Management | podcast | 389 | 779 | 2026-08-08 |
| 587 | Exploring Web Development | livestream | 483 | NULL | 2026-01-10 |
Worked solution and explanation
What this really is
Strip away the content framing and this is a whole-year window over dates stored as text. publish_date holds 'YYYY-MM-DD' strings spanning five years, so with no filter you get all 200 pieces, and comparing the column to the bare year gets you none of them. Anyone can write a WHERE clause. What separates candidates is the boundary: close the window a day early and the year's last pieces disappear from the audit, with no error to warn you.
Step 1: Name the columns the record needs
The ask is the full record, so list all six columns of content_items instead of writing SELECT *. The output is the same today, and the shape stays fixed when someone adds a column next quarter.
Step 2: Bound the year at both ends
publish_date BETWEEN '2026-01-01' AND '2026-12-31' is inclusive on both sides. A piece published on the first day or the last day of the year still belongs to that year, and this check keeps both.
Step 3: Let undated pieces fall out
Twelve rows have a NULL publish_date. BETWEEN evaluates to unknown for them, and WHERE keeps only rows that are true. That is the correct outcome, because a piece with no date was not published in any year.
SELECT
content_id,
title,
content_type,
duration_seconds,
creator_id,
publish_date
FROM content_items
WHERE publish_date BETWEEN '2026-01-01' AND '2026-12-31'One inclusive range on publish_date, every column named.
- Inclusive BETWEEN (day-level dates)
publish_date BETWEEN '2026-01-01' AND '2026-12-31'. This is clean and correct while the column holds plain days.- Half-open window (timestamp-safe)
publish_date >= '2026-01-01' AND publish_date < '2027-01-01'. This catches every instant of the last day, and you never have to reason about the year's final second.
Common follow-up questions
- How would you rewrite this so it stays correct if `publish_date` becomes a timestamp? (Tests whether they reach for the half-open window and understand the inclusive upper-bound trap.)
- Now produce the same audit for the last three years, one row per year with a count of pieces. What changes? (Moves from a flat filter to grouping on the year taken from `publish_date`.)