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
WHERE

Dan Lee
Lesson Objectives
By the end of this lesson, you will:
- Learn how to filter data using WHERE
- Understand comparison operators (=, >, <, >=, <=, !=)
- Write SQL queries to extract specific insights from Netflixâs hit series data
đŹ Scenario: Identifying High-Rated Netflix Series
Your manager at Netflix, Alex, is preparing a report on top-rated shows and wants to filter out lower-performing series.
Alex asks:
Can you retrieve only the shows that have a rating above 8.5? We need to focus on our highest-quality content.
Your job is to query the netflix_series table and provide the requested data.
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 | 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 |
1. Filtering Data with WHERE
The WHERE clause filters rows based on specific conditions. Instead of retrieving every record in a table, we can narrow results based on ratings, release years, or genres.
Syntax
1SELECT column1, column2
2FROM table_name
3WHERE condition;
Example Query: Retrieving Top-Rated Series
1SELECT title, rating
2FROM netflix_series
3WHERE rating > 8.5;
Output Example
title | rating |
---|---|
âStranger Thingsâ | 8.7 |
âDarkâ | 8.8 |
âBreaking Badâ | 9.5 |
âNarcosâ | 8.8 |
âThe Crownâ | 8.6 |
âBlack Mirrorâ | 8.8 |
Whatâs Happening?
- WHERE rating > 8.5 filters the results so that only shows with a rating greater than 8.5 appear.
- The dataset excludes any series with a rating of 8.5 or below.
2. Using Comparison Operators
We can use different operators to refine our filters:
Operator | Description | Example Query |
---|---|---|
= | Equals | WHERE genre = 'Sci-Fi' |
!= | Not equal | WHERE rating != 8.5 |
> | Greater than | WHERE rating > 8 |
< | Less than | WHERE release_year < 2020 |
>= | Greater than or equal to | WHERE seasons >= 3 |
<= | Less than or equal to | WHERE total_views_millions <= 150 |
Example Query: Finding Recent Releases
1SELECT title, release_year
2FROM netflix_series
3WHERE release_year >= 2020;
Output Example
title | release_year |
---|---|
Squid Game | 2021 |
Bridgerton | 2020 |
3. Filtering with Multiple Conditions
The AND and OR operators allow us to combine multiple conditions.
- AND: Only returns rows that match all conditions
- OR: Returns rows that match at least one condition
Example Query: Finding High-Rated Shows Released After 2018
1SELECT title, rating, release_year
2FROM netflix_series
3WHERE rating > 7.5 AND release_year > 2017;
Output Example
title | rating | release_year |
---|---|---|
âSquid Gameâ | 8 | 2021 |
âThe Witcherâ | 7.9 | 2019 |
Whatâs happening?
- AND ensures that both conditions must be true for a row to appear.
- The result excludes any older or lower-rated shows.
Example Query: Finding Either High-Rated or Recent Shows
1SELECT title, rating, release_year
2FROM netflix_series
3WHERE rating > 8.5 OR release_year > 2020;
Output Example
title | rating | release_year |
---|---|---|
âSquid Gameâ | 8 | 2021 |
âStranger Thingsâ | 8.7 | 2016 |
âDarkâ | 8.8 | 2017 |
âBreaking Badâ | 9.5 | 2008 |
âNarcosâ | 8.8 | 2015 |
âThe Crownâ | 8.6 | 2016 |
âBlack Mirrorâ | 8.8 | 2011 |
âď¸ SQL Exercises
Exercise 1: Filtering High-Rated Netflix Series
Alex wants a filtered report showing Netflix series that were released in or after 2017 and have a rating of at least 8.0.
Filter conditions:
- release_year >= 2017
- rating >= 8.0
Expected Output Example:
title | release_year | rating |
---|---|---|
Squid Game | 2021 | 8.0 |
Dark | 2017 | 8.8 |
Money Heist | 2017 | 8.2 |
Write an SQL query to return the requested data.
Exercise 2: Identifying Popular Crime and Sci-Fi Series
Netflix executives want to analyze popular shows in the âCrimeâ and âSci-Fiâ genres. Your task is to retrieve all Netflix series that belong to either of these genres. Order the table in the ascending order of rating.
Filter conditions:
- genre must be âCrimeâ or âSci-Fiâ.
Expected Output Example:
title | genre | rating |
---|---|---|
Money Heist | Crime | 8.2 |
Stranger Things | Sci-Fi | 8.7 |
Narcos | Crime | 8.8 |
Dark | Sci-Fi | 8.8 |
Black Mirror | Sci-Fi | 8.8 |
Breaking Bad | Crime | 9.5 |
Write an SQL query to return the requested data.