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

WHERE

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 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_idtitlegenrerelease_yearseasonsratingtotal_views_millions
1Stranger ThingsSci-Fi201648.7140
2Squid GameThriller202118200
3The WitcherFantasy201937.990
4Money HeistCrime201758.2180
5DarkSci-Fi201738.885

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

titlerating
“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:

OperatorDescriptionExample Query
=EqualsWHERE genre = 'Sci-Fi'
!=Not equalWHERE rating != 8.5
>Greater thanWHERE rating > 8
<Less thanWHERE release_year < 2020
>=Greater than or equal toWHERE seasons >= 3
<=Less than or equal toWHERE total_views_millions <= 150

Example Query: Finding Recent Releases

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

Output Example

titlerelease_year
Squid Game2021
Bridgerton2020

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

titleratingrelease_year
“Squid Game”82021
“The Witcher”7.92019

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

titleratingrelease_year
“Squid Game”82021
“Stranger Things”8.72016
“Dark”8.82017
“Breaking Bad”9.52008
“Narcos”8.82015
“The Crown”8.62016
“Black Mirror”8.82011

✍️ 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:

titlerelease_yearrating
Squid Game20218.0
Dark20178.8
Money Heist20178.2

Write an SQL query to return the requested data.

Upgrade to Pro

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:

titlegenrerating
Money HeistCrime8.2
Stranger ThingsSci-Fi8.7
NarcosCrime8.8
DarkSci-Fi8.8
Black MirrorSci-Fi8.8
Breaking BadCrime9.5

Write an SQL query to return the requested data.

Upgrade to Pro

👉 Found this lesson helpful?