Last Updated: May 12, 2026
For this exercise, we will work with below data:
Using FULL OUTER JOIN, list every user paired with every payment, showing username, payment_id, and amount. Users without payments and payments without users should both appear (with NULLs on the missing side). Order by username (NULLs last), then payment_id.
Using FULL OUTER JOIN on tracks and streams, list every track id along with its stream count (include tracks with zero streams). Show track_id (via COALESCE) and stream_count. Order by stream_count descending, then track_id ascending.
Using FULL OUTER JOIN on users and payments, return every user's username along with their total amount paid. Include users with no payments (treat as 0) and orphan payments (collapse them into one row labeled '(orphan)'). Show username and total_paid. Order by username, with the orphan row placed last using NULLS LAST on the underlying u.username.
Using FULL OUTER JOIN on users and payments, list every distinct country that appears on either side, along with the count of distinct users and the count of payments from that country. Treat a NULL country (orphan payment with no user) as 'Unknown'. Show country, user_count, and payment_count. Order by country.