Tracks That Have Never Been Purchased (Anti-Join)
The catalog team wants to find tracks that have never appeared in any customer purchase, as candidates for promotion or...
Combine rows from two or more tables by matching a shared key.
The catalog team wants to find tracks that have never appeared in any customer purchase, as candidates for promotion or...
Compute each artist's total track count (across all their albums) and rank artists by that count, highest first, using...
HR wants to identify individual contributors -- employees nobody reports to. Using a correlated NOT EXISTS subquery...
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.
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.
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.
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;