AlgoMaster Logo

Exercise: SELF JOIN

Last Updated: May 12, 2026

1 min read

For this exercise, we will work with below data:

SQL

Exercise 1

Easy

Show each artist and the name of their manager using the artists table. Only include artists who have a manager. Order by artist_name.

SQL

Expected Query

Expected Output

Exercise 2

Easy

Show each sub-genre alongside its parent genre name using the genres table. Order by sub_genre.

SQL

Expected Query

Expected Output

Exercise 3

Medium

Find all pairs of users who follow each other on the follows table. Show each pair once with usernames from the users table. Order by user_a.

SQL

Expected Query

Expected Output

Exercise 4

Medium

For each user who has at least one mutual follow, show the username and the number of mutual followers (users they follow who also follow them back). Use a self join on the follows table. Order by mutual_count descending, then username.

SQL

Expected Query

Expected Output

Exercise 5

Hard

Find artists who manage at least one other artist AND who themselves have a manager (middle managers in the hierarchy). Show distinct artist_name. Use the artists table. Order by artist_name.

SQL

Expected Query

Expected Output