Friendly Movies Streamed Last Month - Problem

You are given two tables: TVProgram and Content.

The TVProgram table contains information about TV programs:

  • program_date: The date when the program was aired
  • content_id: The ID of the content
  • channel: The TV channel name

The Content table contains details about each content:

  • content_id: Unique identifier for the content
  • title: The title of the content
  • Kids_content: Whether it's kid-friendly ('Y') or not ('N')
  • content_type: Type of content (movies, series, etc.)

Write a SQL query to find the distinct titles of kid-friendly movies that were streamed in June 2020.

Table Schema

TVProgram
Column Name Type Description
program_date PK date Date when the program was aired
content_id PK int ID of the content (foreign key to Content table)
channel varchar TV channel name
Primary Key: (program_date, content_id)
Content
Column Name Type Description
content_id PK varchar Unique identifier for the content
title varchar Title of the content
Kids_content enum Whether content is for kids: 'Y' (yes) or 'N' (no)
content_type varchar Type of content (movies, series, etc.)
Primary Key: content_id

Input & Output

Example 1 — Kid-friendly Movies in June 2020
Input Tables:
TVProgram
program_date content_id channel
2020-06-10 1 Disney Channel
2020-06-15 2 Nickelodeon
2020-07-01 3 HBO
Content
content_id title Kids_content content_type
1 Moana Y Movies
2 Frozen Y Movies
3 The Dark Knight N Movies
Output:
title
Frozen
Moana
💡 Note:

From the TVProgram table, we find programs aired in June 2020 (2020-06-10 and 2020-06-15). Joining with Content table, both Moana and Frozen are kid-friendly movies (Kids_content = 'Y' and content_type = 'Movies'). The program on 2020-07-01 is excluded as it's in July.

Example 2 — Mixed Content Types
Input Tables:
TVProgram
program_date content_id channel
2020-06-05 4 Cartoon Network
2020-06-20 5 Disney XD
Content
content_id title Kids_content content_type
4 Tom and Jerry Y Series
5 Toy Story Y Movies
Output:
title
Toy Story
💡 Note:

Both programs aired in June 2020 and are kid-friendly, but only 'Toy Story' is a movie. 'Tom and Jerry' is excluded because it's a series, not a movie.

Example 3 — No Results
Input Tables:
TVProgram
program_date content_id channel
2020-06-12 6 Adult Swim
Content
content_id title Kids_content content_type
6 Deadpool N Movies
Output:
title
💡 Note:

Although 'Deadpool' is a movie that aired in June 2020, it's not kid-friendly (Kids_content = 'N'), so no results are returned.

Constraints

  • program_date is in format YYYY-MM-DD
  • Kids_content is either 'Y' or 'N'
  • content_type includes 'Movies', 'Series', etc.
  • Multiple programs can have the same content_id on different dates

Visualization

Tap to expand
Friendly Movies Streamed Last Month INPUT TABLES TVProgram Table program_date content_id 2020-06-10 1 2020-06-15 2 2020-06-20 3 2020-05-25 4 Content Table id title kids type 1 Toy Story Y Movies 2 Breaking Bad N Series 3 Finding Nemo Y Movies 4 Frozen Y Movies 5 Action Hero N Movies ALGORITHM STEPS 1 JOIN Tables Link TVProgram with Content ON content_id = id 2 Filter by Date June 2020 only BETWEEN '2020-06-01' AND '2020-06-30' 3 Filter Content Kids = 'Y' AND type = 'Movies' Kids=Y Movies 4 Select DISTINCT Get unique movie titles SELECT DISTINCT title SELECT DISTINCT title FROM TVProgram t JOIN Content c ON... FINAL RESULT Kid-Friendly Movies Streamed in June 2020 Toy Story 2020-06-10 Finding Nemo 2020-06-20 Excluded: Breaking Bad - Not for kids Frozen - Not in June 2020 Result: 2 Distinct Titles OK - Query Complete Key Insight: Use INNER JOIN to combine TVProgram and Content tables on content_id. Apply WHERE clause to filter for June 2020 dates, kid-friendly content (Kids_content = 'Y'), and content type = 'Movies'. DISTINCT ensures no duplicate titles in the result set. TutorialsPoint - Friendly Movies Streamed Last Month | Optimal Solution
Asked in
Netflix 15 Disney 12 Amazon 8
25.4K Views
Medium Frequency
~12 min Avg. Time
890 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen