PRO SQL Modules
SQL Basics1h 20m • 4 lessons
Multiple Tables1h 40m • 5 lessons
Query Restructuring40m • 2 lessons
Data Transformation1h 40m • 5 lessons
Analytical SQL2h • 6 lessons
LIMIT

Dan Lee
Lesson Objectives
By the end of this lesson, you will:
- Learn how to restrict the number of rows returned using LIMIT and OFFSET
- Write SQL queries to retrieve the top Netflix series based on rating and viewership
🎬 Scenario: Finding the Top Netflix Series
Your manager at Netflix, Alex, wants a quick snapshot of the top 3 most-watched series. Instead of returning the entire dataset, they only need a short list.
Alex asks:
Can you get me the top 3 most-viewed Netflix series? We don’t need the full list, just the biggest hits.
Your task is to use LIMIT or OFFSET to retrieve only the highest-performing series from the netflix_series table.
series_id | title | genre | release_year | seasons | rating | total_views_millions |
---|---|---|---|---|---|---|
1 | Stranger Things | Sci-Fi | 2016 | 4 | 8.7 | 140 |
2 | Squid Game | Thriller | 2021 | 1 | 8.0 | 200 |
3 | The Witcher | Fantasy | 2019 | 3 | 7.9 | 90 |
4 | Money Heist | Crime | 2017 | 5 | 8.2 | 180 |
5 | Dark | Sci-Fi | 2017 | 3 | 8.8 | 85 |
6 | Bridgerton | Drama | 2020 | 2 | 7.3 | 100 |
7 | Breaking Bad | Crime | 2008 | 5 | 9.5 | 120 |
8 | Narcos | Crime | 2015 | 3 | 8.8 | 75 |
9 | The Crown | Drama | 2016 | 5 | 8.6 | 95 |
10 | Black Mirror | Sci-Fi | 2011 | 6 | 8.8 | 110 |
1. Limiting Results with LIMIT
The LIMIT keyword restricts the number of rows returned by a query. It is supported in MySQL and PostgreSQL.
Syntax
1SELECT column1, column2
2FROM table_name
3ORDER BY column_name DESC
4LIMIT n;
- LIMIT n returns only the first n rows of the result set.
- It is usually combined with ORDER BY to return the top or bottom results.
2. Retrieving the Top 3 Most-Watched Series
To return the top 3 Netflix series by viewership, we use LIMIT 3.
Example Query
1SELECT title, total_views_millions
2FROM netflix_series
3ORDER BY total_views_millions DESC
4LIMIT 3;
Output Example
title | total_views_millions |
---|---|
Squid Game | 200 |
Money Heist | 180 |
Stranger Things | 140 |
What’s Happening?
- The query sorts series by total views in descending order.
- Only the first 3 results are displayed.
3. Using LIMIT with OFFSET
The OFFSET clause allows pagination, meaning you can skip a set number of rows before returning results.
Example Query: Finding the 4th to 6th Most-Watched Series
1SELECT title, total_views_millions
2FROM netflix_series
3ORDER BY total_views_millions DESC
4LIMIT 3 OFFSET 3;
Output Example
title | total_views_millions |
---|---|
Breaking Bad | 120 |
Black Mirror | 110 |
Bridgerton | 100 |
What’s Happening?
- OFFSET 3 skips the first 3 rows.
- LIMIT 3 returns the next 3 rows, effectively showing the 4th to 6th most-watched series.
✍️ SQL Exercises
Exercise 1: Top 5 Highest-Rated Netflix Series
Alex, your manager at Netflix, wants to know which shows have received the highest audience ratings. Write an SQL query to retrieve the top 5 highest-rated Netflix series, sorted by rating in descending order.
Expected Output Example:
title | genre | rating |
---|---|---|
Breaking Bad | Crime | 9.5 |
Dark | Sci-Fi | 8.8 |
Black Mirror | Sci-Fi | 8.8 |
Narcos | Crime | 8.8 |
Stranger Things | Sci-Fi | 8.7 |
Write an SQL query to return the requested data.
Exercise 2: Recent Netflix Users
Netflix wants to see the most recent signups to track new users. Write an SQL query to retrieve the 5 most recent users who signed up, sorted by signup_date in descending order.
Expected Output Example:
name | signup_date |
---|---|
David Kim | 2023-01-05T00:00:00 |
Emma Garcia | 2022-07-18T00:00:00 |
Bob Smith | 2021-02-22T00:00:00 |
Alice Johnson | 2020-05-10T00:00:00 |
Charlie Lee | 2019-09-13T00:00:00 |
Write an SQL query to return the requested data.