AlgoMaster Logo

Exercise: Correlated Subqueries

Last Updated: May 12, 2026

1 min read

For this exercise, we will work with below data:

SQL

Exercise 1

Easy

Find tracks whose duration_seconds is greater than the average duration of tracks on the same album. Use a correlated subquery in WHERE. Show the track title and duration_seconds, ordered by track_id

SQL

Expected Query

Expected Output

Exercise 2

Easy

For each artist, show their name and follower count. Use a correlated subquery against artist_follows in the SELECT list. Order by follower count descending, then by name ascending.

SQL

Expected Query

Expected Output

Exercise 3

Medium

Find each user's most recent payment. Use a correlated subquery on MAX(payment_date). Show the username, payment amountpayment_date, and status. Order by payment_date descending, then by username.

SQL

Expected Query

Expected Output

Exercise 4

Medium

Find tracks whose duration is below the average duration of tracks on the same album. Use a correlated subquery in WHERE. Show the track titlealbum_id, and duration_seconds, ordered by album_id.

SQL

Expected Query

Expected Output