› Forums › SQL › Q: In this SQL query, does the second `strftime()` help find the first episode released each year?
- This topic is empty.
Viewing 1 post (of 1 total)
-
AuthorPosts
-
December 30, 2025 at 10:59 am #5910
Context Code
SELECT strftime('%Y', air_date) AS year, strftime('%m-%d', MIN(air_date)) AS first_release FROM episodes GROUP BY year;
Answer
No — the second
strftime()does not help find the first episode of each year.The earliest episode per year is found by
MIN(air_date), not bystrftime().
Explanation in Simple Terms
This query has three different jobs, and each part does only one job.
1. Extracting the year
strftime('%Y', air_date)- Runs on every row
- Extracts the year from
air_date - Does not remove or filter rows
2. Grouping episodes by year
GROUP BY year- Combines all episodes from the same year into one group
- Creates one output row per year
- Still does not decide which episode is chosen
3. Finding the first episode of the year
MIN(air_date)- Looks inside each year group
- Selects the earliest air date
- This is the step that actually finds the first episode
4. Formatting the result
strftime('%m-%d', MIN(air_date))- Converts the earliest date into
month-dayformat - Only affects display
- Has no role in selecting rows
Why the confusion happens
Because the query outputs the first day of the year, it can feel like:
“The second
strftime()found the first episode.”But in reality:
- The episode is already chosen by
MIN(air_date) strftime()just makes the date look nicer
Important Rule to Remember
SQL Component Selects the first row? strftime()❌ No GROUP BY❌ No MIN()✅ Yes
One-Sentence Takeaway
MIN(air_date)determines the first episode released each year, whilestrftime()only formats the date and never influences which row is selected.
-
AuthorPosts
Viewing 1 post (of 1 total)
- You must be logged in to reply to this topic.

