AlgoMaster Logo

Exercise: EXISTS, NOT EXISTS, IN, and NOT IN

Last Updated: May 12, 2026

1 min read

For this exercise, we will work with below data:

SQL

Exercise 1

Easy

Find all users who have streamed at least one track. Use EXISTS against the streams table. Show the username, ordered alphabetically.

SQL

Expected Query

Expected Output

Exercise 2

Easy

Find users who do not follow any artist. Use NOT EXISTS against artist_follows. Show the username.

SQL

Expected Query

Expected Output

Exercise 3

Medium

Find artists who have at least one album that was streamed by a premium user. Use EXISTS joining through albumstracksstreams, and users. Show the artist name ordered alphabetically.

SQL

Expected Query

Expected Output

Exercise 4

Medium

Find tracks that are not on any playlist. Use NOT EXISTS against playlist_tracks. Show the track title.

SQL

Expected Query

Expected Output

Exercise 5

Hard

Find artists who have not released any album after 2024-01-01. Use NOT IN against albums.artist_id, which is NOT NULL and therefore safe. Show the artist name ordered alphabetically.

SQL

Expected Query

Expected Output