Albums with Artist Names
The current album data only contains an ArtistId, but users want to see the actual artist name alongside each album....
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.
The current album data only contains an ArtistId, but users want to see the actual artist name alongside each album....
The recommendation system needs track data enriched with genre information. Currently, tracks only have a GenreId. You...
The customer service team needs to see purchase history. They want to see each invoice along with the customer's name...
The content team wants to understand the distribution of tracks across different Genre. Which genres have the most...
The data science team is analyzing listening patterns. They want to know the average track length for each genre. Some...
The editorial team is writing a feature about the most prolific artists in the catalog. Find artists who have released...
Create a leaderboard of artists ranked by how many albums they've released. Artists with the same number of albums...
The marketing team wants to segment customers into 4 groups (quartiles) based on their total spending. This will help...
Use a CTE to find the longest track in each genre. CTEs are especially useful when you need to reference aggregated...
Use multiple CTEs to perform a comprehensive customer analysis: calculate total spending and invoice count, then...
The Employee table has a self-referencing ReportsTo column. Use a self-join to show each employee alongside their...
Find pairs of customers who live in the same city. This can help with organizing local meetups or referral programs....
Find genres that are both popular (many tracks) AND have high-quality tracks (high average file size). Use HAVING with...
Calculate each genre's share of total tracks as a percentage. This requires comparing individual counts to the overall...
An INNER JOIN only returns matching rows. Use LEFT JOIN to include ALL artists, even those without any albums. Write a...
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.
SELECT c.name
FROM customers c
WHERE NOT EXISTS (
SELECT 1 FROM orders o WHERE o.customer_id = c.id
);A filter on the right table in WHERE removes the NULL rows a LEFT JOIN creates, so it behaves like an INNER JOIN.
-- 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;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.