Topics / 🗄️ SQL, pandas & Data Analysis / 🗄️ Level 14: SQL Fundamentals

SQL exercise · about 5 minutes · free

LEFT JOIN: Don't Lose the Rookie

A new player has no matches yet. An INNER JOIN silently drops them from your report. A LEFT JOIN keeps them.

LEFT JOIN keeps every row from the left table, filling missing right-side values with NULL. COUNT(column) ignores NULLs, so players with no matches count as 0.

Venn diagram of players and matches. LEFT JOIN keeps every player; COUNT(m.id) gives Rookie 0playersmatchesRookie → 0KaiMiaZedAliNovaBot9LEFT JOIN keeps every player; COUNT(m.id) gives Rookie 0
🌍 Real-life storyReal-life story: "customers with zero orders" vanishing from reports is a classic bug. Interviewers test it constantly.
Your quest: Show every player's name and number of matches as matches_played, including players with 0.
Database: players(id, name, class, level, country) · matches(id, player_id, map, kills, deaths, score) · orders(id, player_id, order_date, item, amount) · app_events(user_id, event, day) · employees(id, name, dept, salary, manager_id, hire_date) · logins(user_id, day) · payment_events(payment_id, user_id, amount, status, updated_at)
Try it now Runs in your browser. No sign-in needed. Ctrl+Enter to run.
HintFROM players p LEFT JOIN matches m ON m.player_id = p.id GROUP BY p.name, counting m.id (not *).
Output appears here.

Open it in the full course → Free with Google: saves your progress and unlocks 627 lessons.

In this level you'll learn:
More in Level 14: SQL Fundamentals

Share on LinkedIn