Streamhub's finance team needs a complete view of the user and conversion tables, in both directions:
- Users who have never converted (conversion amount will be
NULL). - Conversions with no user match (user ID will be
NULL).
Write a query to return the user ID and conversion amount for every row in the combined view.
Assumptions:
- The
userstable contains every account on the platform. - The
conversionstable records each paid conversion event.
Output:
- One row per matched pair, plus one row per user with no conversions, plus one row per conversion with no user match, with columns
user_idandamount.
Schema · analytics 5 tables
Run previews · Check grades
Write a query, then run it to see results here.
Worked solution Try it yourself first
SELECT
u.id AS user_id,
cv.amount
FROM
users u
FULL OUTER JOIN conversions cv ON u.id = cv.user_id The shape
A FULL OUTER JOIN between users and conversions keeps every row from both tables. Users who have converted appear with their amount; users who have never converted appear with amount as NULL; conversions whose user_id doesn't resolve to a real user appear with user_id as NULL. Three categories of rows, one query — exactly the cross-table reconciliation Streamhub's finance team is after.
Clause by clause
SELECT u.id AS user_id, cv.amountreturns one column from each side. On matched rows both values are real. On a never-converted user,amountisNULL. On a conversion that points to no user,user_idisNULL. TheNULLpatterns are how finance reads which category each row belongs to.FROM users u FULL OUTER JOIN conversions cv ON u.id = cv.user_idis the join. TheONcondition pairs a user with each of their conversions. Where it matches, the row is assembled from both sides. Where it doesn't, the outer join preserves the row andNULL-pads the missing side — andFULLmakes that guarantee in both directions, so neither table loses rows.- No
WHERE. The team asked for the combined view of both tables, so every row the join produces belongs in the output.
You practiced FULL OUTER JOIN in a different domain. The same shape applies anywhere two datasets need to be compared as peers — neither one is the "primary," both contribute orphan rows to the result.