Three-Table JOIN: Complete Track Info
Join three tables to create a comprehensive track view with album title, artist name, and track details. Write a query...
Join three tables to create a comprehensive track view with album title, artist name, and track details. Write a query...
Create a detailed invoice line report joining Invoice, InvoiceLine, Track, and Customer tables. Write a query that...
Count how many unique composers have created Rock music. Use COUNT with DISTINCT to count unique values. Write a query...
Find all tracks that are either Rock OR Metal genre. Use OR to match either condition. Write a query to find tracks in...
For each album, find the shortest and longest track durations. This helps identify albums with consistent vs. varied...
Understand the difference between WHERE (filters rows before grouping) and HAVING (filters groups after aggregation)....
The executive team wants to understand revenue distribution across music genres. For each genre, calculate the total...
The marketing team wants to identify above-average spenders within each country to target premium campaigns. Compare...
The international marketing team needs to know the most popular music genre in each country by purchase count. This...
The CRM team wants to segment customers into value tiers based on their lifetime spending. Classify each customer as...
Management wants to compare the sales performance of support representatives. Calculate each rep's customer count,...
The product team wants to identify customers with the most diverse music taste — those who listen across many genres....
The data team discovered that some artists have tracks in multiple genres. Find these cross-genre artists and show...
The recommendation team wants a leaderboard of the most prolific artists measured by total tracks across all their...
Editorial wants a track-length profile per genre, restricted to genres with a meaningful catalog so single-track...
Track your streak & earn XP
Sign up free to unlock your progress dashboard, daily streaks, and leaderboard ranking.
10 role-based tests for Data Analysts, SQL Developers & Data Engineers with instant scorecards.
Combine rows from two or more tables by matching a shared key.
A join combines rows from two or more tables by matching values in a shared key column. INNER JOIN keeps only the rows that match on both sides, LEFT JOIN keeps every row from the left table and fills the missing columns with NULL, and an anti-join finds rows with no match at all by adding WHERE right.id IS NULL. These questions cover the join shapes that actually show up in analytics work: fact-to-dimension lookups, self-joins over a hierarchy, and three- and four-table chains.
FAQ
Short answers to what people get stuck on most. Tap a question to expand it.
INNER JOIN keeps only rows that match in both tables. LEFT JOIN keeps every row from the left table, with NULLs where the right table has no match.
SELECT c.name, o.id AS order_id
FROM customers c
LEFT JOIN orders o ON o.customer_id = c.id;
-- customers with no orders show order_id = NULLUse an anti-join: keep the rows from table A that have no partner in table B.
A filter on the right table in WHERE removes the NULL rows a LEFT JOIN creates, so it behaves like an INNER JOIN.
SELECT c.name
FROM customers c
WHERE NOT EXISTS (
SELECT 1 FROM orders o WHERE o.customer_id = c.id
);-- keeps every customer, even those with no order over 100
SELECT c.name, o.amount
FROM customers c
LEFT JOIN orders o
ON o.customer_id = c.id AND o.amount > 100;