AlgoMaster Logo

Exercise: Filtering with WHERE

Last Updated: May 10, 2026

1 min read

For this exercise, we will work with below data:

SQL

Exercise 1

Easy

From the users table, find every user on the premium subscription tier. Return usernamecountry, and subscription_tier.

SQL

Expected Query

Expected Output

Exercise 2

Easy

From the users table, find every user whose country is NOT 'US'. Return username and country.

SQL

Expected Query

Expected Output

Exercise 3

Easy

From the users table, find every user whose timezone is NULL. Return usernamecountry, and timezone.

SQL

Expected Query

Expected Output

Exercise 4

Easy

From the streams table, find every stream where duration_listened is greater than 200 seconds. Return stream_iduser_id, and duration_listened

SQL

Expected Query

Expected Output

Exercise 5

Medium

From the users table, find every user who signed up on or after 2024-01-01. Return username and signup_date, ordered by signup_date ascending.

SQL

Expected Query

Expected Output

Exercise 6

Medium

From the streams table, find streams where duration_listened is at least 180 seconds but strictly less than 300 seconds. Return stream_iduser_id, and duration_listened, ordered by duration_listened descending.

SQL

Expected Query

Expected Output

Exercise 7

Medium

From the users table, find every user who is NOT from the 'US', including users with NULL country. Return username and country, ordered by username ascending.

SQL

Expected Query

Expected Output

Exercise 8

Hard

From the users table, find every user who is from 'US' and NOT on the 'free' tier, OR who is on the 'family' tier (regardless of country). Return usernamecountry, and subscription_tier. Use parentheses to make the precedence explicit.

SQL

Expected Query

Expected Output