AlgoMaster Logo

Exercise: RIGHT JOIN

Last Updated: May 12, 2026

1 min read

For this exercise, we will work with below data:

SQL

Exercise 1

Easy

Using RIGHT JOIN, list every user along with their stream_id. Users with no streams should still appear with NULL for stream_id. Show username and stream_id. Order by username, then stream_id. Use streams and users.

SQL

Expected Query

Expected Output

Exercise 2

Easy

Using RIGHT JOIN, find all tracks that have never been streamed. Show only the track title. Use streams and tracks.

SQL

Expected Query

Expected Output

Exercise 3

Medium

Using RIGHT JOIN, list every genre with the number of albums in that genre (album_count). Include genres with zero albums. Show genre and album_count. Order by album_count descending, then genre ascending. Use albums and genres.

SQL

Expected Query

Expected Output

Exercise 4

Medium

Using RIGHT JOIN, list every user with the count of playlists they have created (playlist_count). Include users who have created no playlists. Show username and playlist_count. Order by playlist_count descending, then username ascending. Use playlists and users.

SQL

Expected Query

Expected Output

Exercise 5

Hard

Using RIGHT JOIN, return each artist's name along with their stream_count (total streams across all their tracks). Include artists with no streams. Show artist and stream_count. Order by stream_count descending, then artist ascending. Walk the chain streams -> tracks -> albums -> artists.

SQL

Expected Query

Expected Output