Last Updated: May 12, 2026
For this exercise, we will work with below data:
Use LATERAL to find the most recent stream for each user from the users and streams tables. Show username, track_id, and started_at. Include users with no streams (show NULLs). Order by username.
Use LATERAL to find each user's highest-amount subscription from the subscriptions table. Show username and amount. Include users with no subscription (NULL amount). Order by username.
Use LATERAL to find the 3 most recent streams per user with track title and artist name from the users, streams, tracks, albums, and artists tables. Show username, track_title, artist_name, and started_at. Only include users who have at least one stream. Order by username, then started_at descending.
Use LATERAL to find each artist's most recent album. Show artist_name, album_title, and release_date. Use the artists and albums tables. Order by artist_name.