SQL Practice: Filtering and Sorting a Movie Catalog
Same skills, new shelves: put SELECT, WHERE, and ORDER BY to work on a movie catalog.
Most of the last eleven chapters ran on 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_breaker Schema · Movie Rentals Table · movies 5 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.
Run your query to inspect the result.
Expected answer
- Columns: title, genre, release_year, rating.
- Rows: 4 movies rated 8.0 or higher.
- The first row should be Paper Lanterns at 8.7.
Related
Comparisons, AND/OR, IN, BETWEEN, and LIKE.
SELECT, WHERE, ORDER BY, and LIMIT at a glance.
Debug filters that match nothing.
Nested SELECTs, IN, EXISTS, and correlation.
UNION, UNION ALL, INTERSECT, and EXCEPT.
A stray NULL drops every row. Use NOT EXISTS.