Last Updated: May 12, 2026
For this exercise, we will work with below data:
Using UNION ALL, write a query that builds a unified follow feed combining follows and artist_follows. Show user_id (the follower), follow_type ('user' or 'artist'), target_id, and followed_at. Order by followed_at descending.
Using UNION ALL, return all country values from users and artists together. Include rows even if the same country appears in both tables. Show country ordered alphabetically with NULLs last.
Using UNION ALL, build a combined event timeline for alice_m (user_id = 1). For payments use 'payment' as event_type and the amount column; for streams use 'stream' and NULL for amount. Show event_type, event_date, and amount. Order by event_date, then event_type.
Using UNION ALL, write a query that returns the 5 most recent platform activities, where an activity is either a stream ('stream'), a user follow ('user_follow'), or an artist follow ('artist_follow'). Show username, activity_type, and activity_time. Order by activity_time descending and limit to 5 rows.
Using UNION ALL, write a query that returns each user's total revenue contribution and total stream count side by side. For each user, sum amount for completed payments and count their streams. Show user_id, total_paid, and total_streams. Include only users who appear in users and have at least one event in either source. Order by user_id.