New Kids-Safe Originals for the Family Row — SQL Problem
The home screen of an OTT video app has a "Family Originals" row.
- Difficulty: Easy
- Topics: Basics
- Dialect: MySQL
- Problem: #473
Problem statement
The home screen of an OTT video app has a "Family Originals" row. A title belongs in it when it is one of the service's own originals, its certificate is U or U/A 7+, and it was released in 2023 or later.
Return the columns title_id and title_name of every title that qualifies. Titles produced by other studios (is_original = 0) never qualify, whatever their certificate. Return the rows in any order.
Tables
Table: Title
| Column | Type |
|---|---|
| title_id | int |
| title_name | varchar |
| kind | enum(movie, series) |
| maturity_rating | enum(U, U/A 7+, U/A 13+, U/A 16+, A) |
| release_year | int |
| is_original | bool |
Primary key: title_id.
One row per title in the catalogue. is_original is 1 for the service's own productions, 0 for licensed titles.
Examples
Example 1
Title
| title_id | title_name | kind | maturity_rating | release_year | is_original |
|---|---|---|---|---|---|
| 1 | Little Astronauts | series | U | 2024 | 1 |
| 2 | Midnight Mumbai | series | A | 2024 | 1 |
| 3 | Paper Boats | movie | U/A 7+ | 2023 | 1 |
| 4 | Ocean Kids | series | U | 2022 | 1 |
| 5 | Space Monkeys | movie | U | 2025 | 0 |
| 6 | Rangoli | movie | U/A 13+ | 2023 | 1 |
| 7 | Kites Over Jaipur | movie | U/A 7+ | 2025 | 1 |
Output
| title_id | title_name |
|---|---|
| 1 | Little Astronauts |
| 3 | Paper Boats |
| 7 | Kites Over Jaipur |
How to solve New Kids-Safe Originals for the Family Row
This is a pure filter over one table: no join, no grouping. Each row is checked against three conditions and kept only if every one holds, so they are combined with AND.
The certificate test allows two values. maturity_rating IN ('U', 'U/A 7+') is shorthand for two equalities joined by OR; if you write the OR form yourself, wrap it in parentheses, because AND binds tighter than OR and a AND b OR c would let any U/A 7+ title in regardless of the other conditions. The year test is inclusive — a title from 2023 belongs in the row — so it is >= 2023 (or > 2022).
is_original is a 0/1 flag, so is_original = 1 keeps the service's own productions. The query reads every row once; on a large catalogue an index on (is_original, release_year) would let the engine skip most of it.
Reference solution (MySQL)
SELECT title_id, title_name
FROM Title
WHERE is_original = 1
AND maturity_rating IN ('U', 'U/A 7+')
AND release_year >= 2023Another way
SELECT title_id, title_name FROM Title WHERE is_original = 1 AND (maturity_rating = 'U' OR maturity_rating = 'U/A 7+') AND release_year > 2022Another way
SELECT title_id, title_name FROM Title WHERE is_original <> 0 AND release_year BETWEEN 2023 AND 9999 AND maturity_rating NOT IN ('U/A 13+', 'U/A 16+', 'A')← Orange Cap Leader After Every Match Day · Profiles With No Streams Since the New Year →