Your first SELECT
Hook
You can’t answer questions about football until you can pull a single row out of a
table. SELECT is the door. Everything you do for the next four levels starts here.
Concept
A SQL query says four things, in order:
- What columns you want —
SELECT player_display_name, rushing_yards - From which table —
FROM weekly_stats - Which rows —
WHERE recent_team = 'DET' AND week = 1 AND season = 2024 - In what order —
ORDER BY rushing_yards DESC
Only the first two are required. The rest are filters and sorting on top.
SELECT player_display_name, rushing_yardsFROM weekly_statsWHERE recent_team = 'DET' AND week = 1 AND season = 2024ORDER BY rushing_yards DESC;The column names look long because nflverse named them precisely:
player_display_name instead of player, recent_team instead of team.
That’s the schema — get used to typing them.
Lions example
The Lions opened the 2024 season on the road against the Rams — a Sunday-night 26-20 OT loss in LA. To find every Detroit player with rushing yards that night:
SELECT player_display_name, rushing_yards, rushing_tdsFROM weekly_statsWHERE recent_team = 'DET' AND season = 2024 AND week = 1ORDER BY rushing_yards DESC;Expected shape: a small table with David Montgomery and Jahmyr Gibbs at the top, then a few smaller contributors.
Try it
Write a query that returns every Lions receiver with receiving yards in Week 1 of 2024, sorted from most to least.
You’ll want receiving_yards instead of rushing_yards, and you can leave the
WHERE clause structure the same.
Common mistakes
- Forgetting the season filter.
weekly_statshas every year nflverse has loaded. WithoutAND season = 2024you’ll get a decade of Week 1s. - Using
teaminstead ofrecent_team. The nflverse weekly stats table usesrecent_teamfor the player’s team at that point in time. Watch the column name. - Sorting before filtering in your head. SQL evaluates
WHEREbeforeORDER BY, but you should think filter-first too — narrow the rows, then sort what’s left.
Quick check
- What does
SELECT *return? When should you avoid it? - If you remove
ORDER BY rushing_yards DESCfrom the example above, what happens to the result? - Which column would you change to find passing leaders instead of rushing leaders?