SQL Practice: Filtering and Sorting a Movie Catalog
Same skills, new shelves: put SELECT, WHERE, and ORDER BY to work on a movie catalog.
You have spent ten chapters in the Garden Shop. This chapter hands you a brand-new dataset: a small Movie Rentals shop, so you can prove the skills transfer to data you have never seen. Nothing new to learn here: just the same tools on a fresh problem.
The movies table has one row per film, with a genre, a release_year, and a numeric rating. That is everything a top-rated list needs.
Filter first, then sort
A ranked shortlist is two steps: keep the rows you care about with WHERE, then arrange them with ORDER BY. When several rows share the top value, add a second sort column so the order is stable every time the query runs.
select columns
from table_name
where condition
order by sort_column desc, tie_breakerSchema · Movie RentalsTable · movies5 columns · 12 rows
One row per movie in the catalog.
From movies, return the title, genre, release year, and rating for every film rated 8.0 or higher, highest rating first. Break ties by title.
- Columns: title, genre, release_year, rating.
- Rows: 4 movies rated 8.0 or higher.
- The first row should be Paper Lanterns at 8.7.