Last Updated: May 10, 2026
For this exercise, we will work with below data:
Return the 3 shortest tracks from the tracks table. Show title and duration_seconds, sorted from shortest to longest.
Return the 5 most recently signed up users. Show user_id, username, and signup_date, ordered from newest to oldest.
Return page 2 of streams using OFFSET pagination with a page size of 5, sorted by stream_id ascending. Show stream_id, user_id, and started_at.
For each track in the tracks table, compute its duration in minutes (as duration_seconds / 60.0) and return the 5 longest tracks. Show title, duration_seconds, and the computed duration_minutes aliased value, sorted by duration_minutes descending.
Return artists sorted alphabetically by country, but place artists with a NULL country at the very end. Use a CASE expression so the query works on databases that do not support NULLS LAST. Show name and country.
Write a query using keyset pagination that returns the next 5 streams after stream_id = 10, sorted ascending. Show stream_id, user_id, and started_at.
Implement keyset pagination on the streams table sorted by started_at DESC, stream_id DESC. The previous page ended at started_at = '2024-03-03 14:00:00+00' and stream_id = 13. Return the next 5 rows. Show stream_id, user_id, and started_at.