Last Chance to Join Data Science Interview MasterClass (this week) 🚀 | Just 2 spots remaining...

PRO SQL Modules

SQL Basics
1h 20m • 4 lessons
  1. SQL SELECT
  2. LIMIT
  3. ORDER BY
  4. DISTINCT
Data Filtering
1h 20m • 4 lessons
  1. WHERE
  2. LIKE
  3. IN
  4. BETWEEN
Aggregations
40m • 2 lessons
  1. GROUP BY
  2. HAVING
Multiple Tables
1h 40m • 5 lessons
  1. INNER JOIN
  2. LEFT & RIGHT JOIN
  3. FULL OUTER JOIN
  4. SELF JOIN
  5. INTERSECT & EXCEPT
Query Restructuring
40m • 2 lessons
  1. Subquery
  2. Common Table Expressions (CTE)
Data Transformation
1h 40m • 5 lessons
  1. CASE
  2. String
  3. Date Manipulation
  4. Math Operations
  5. COALESCE
Analytical SQL
2h • 6 lessons
  1. Ranking - ROW_NUMBER(), RANK(), DENSE_RANK()
  2. Running Totals
  3. LAG and LEAD
  4. FIRST_VALUE, LAST_VALUE, Nth_VALUE
  5. PARTITION BY
  6. SQL BETWEEN and PRECEDING
Unlock Premium
FREE

BETWEEN

Course Author Daniel Lee
Instructor

Dan Lee

Learn SQL for free with interactive exercises designed to help aspiring Data Engineers, Data Analysts, and Data Scientists. Learn the basics and advanced SQL concepts by solving real-world problems from MANGO (Meta, Amazon, Netflix, Google, OpenAI)

Lesson Objectives

By the end of this lesson, you will:

  • Learn how to filter numeric and date ranges using BETWEEN
  • Understand how BETWEEN simplifies range conditions compared to multiple comparisons
  • Write SQL queries to find Netflix series within a specific release year or rating range

🎬 Scenario: Finding Mid-Range Netflix Releases

Your manager at Netflix, Alex, is analyzing mid-era releases and wants to focus on shows released between 2015 and 2020.

Alex asks:

Can you retrieve all Netflix series that were released between 2015 and 2020?

Your task is to query the netflix_series table and provide the requested data.

series_idtitlegenrerelease_yearseasonsratingtotal_views_millions
1Stranger ThingsSci-Fi201648.7140
2Squid GameThriller202118200
3The WitcherFantasy201937.990
4Money HeistCrime201758.2180
5DarkSci-Fi201738.885

1. Filtering Data with BETWEEN

The BETWEEN operator filters results within a specified range, including both the lower and upper values.

Syntax

1SELECT column1, column2  
2FROM table_name  
3WHERE column_name BETWEEN value1 AND value2;
  • BETWEEN value1 AND value2 includes both value1 and value2 in the result.
  • It’s equivalent to: WHERE column_name >= value1 AND column_name <= value2;

2. Using BETWEEN for Release Year Filtering

Instead of writing:

1SELECT title, release_year  
2FROM netflix_series  
3WHERE release_year >= 2015 AND release_year <= 2020;

You can write:

1SELECT title, release_year  
2FROM netflix_series  
3WHERE release_year BETWEEN 2015 AND 2020;
titlerelease_year
Narcos2015
Stranger Things2016
The Crown2016
Money Heist2017
Dark2017
The Witcher2019
Bridgerton2020

What’s Happening?

  • BETWEEN 2015 AND 2020 filters results to only include release years from 2015 to 2020.
  • The same query using >= and <= would be longer and harder to read.

3. Using BETWEEN for Ratings

You can also apply BETWEEN to numeric values like ratings.

Example Query: Finding Shows with Ratings Between 8.0 and 9.0

1SELECT title, rating  
2FROM netflix_series  
3WHERE rating BETWEEN 8.0 AND 9.0;
titlerating
“Stranger Things”8.7
“Squid Game”8
“Money Heist”8.2
“Dark”8.8
“Narcos”8.8
“The Crown”8.6
“Black Mirror”8.8

What’s Happening?

  • BETWEEN 8.0 AND 9.0 filters results to only include shows with ratings between 8.0 and 9.0.
  • The query still includes 8.0 and 9.0.

✍️ SQL Exercises

Exercise 1: Finding Shows Released Between 2015 and 2020

Alex wants a report showing all series released between 2015 and 2020, sorted by release_year in ascending order, then title in ascending order.

Filter condition:

  • release_year must be between 2015 and 2020.
  • Sort by release_year in ascending order, then title in ascending order.
titlerelease_year
Narcos2015
Stranger Things2016
The Crown2016
Money Heist2017
Dark2017
The Witcher2019
Bridgerton2020

Write an SQL query to return the requested data.

Upgrade to Pro

Exercise 2: Finding Shows with Ratings Between 8.0 and 9.0

Alex wants to focus on highly-rated Netflix shows that have ratings between 8.0 and 9.0.

Filter condition:

  • rating must be between 8.0 and 9.0.
  • Sort by rating in ascending order, then title in ascending order.
titlerating
“Squid Game”8
“Money Heist”8.2
“The Crown”8.6
“Stranger Things”8.7
“Black Mirror”8.8
“Dark”8.8
“Narcos”8.8

Write an SQL query to return the requested data.

Upgrade to Pro
👉 Found this lesson helpful?