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
IN

Dan Lee
Lesson Objectives
By the end of this lesson, you will:
- Learn how to filter data using IN for multiple values
- Understand when to use IN instead of multiple OR conditions
- Write SQL queries to find Netflix series based on specific genres and ratings
🎬 Scenario: Identifying Popular Crime and Sci-Fi Series
Your manager at Netflix, Alex, wants to analyze the most popular Crime and Sci-Fi series to identify trends among viewers.
Alex asks:
Can you retrieve all Netflix series that belong to either the ‘Crime’ or ‘Sci-Fi’ genres?
Your task 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 IN
The IN operator allows you to filter data based on multiple values. Instead of using multiple OR conditions, IN makes queries cleaner and more efficient.
Syntax:
1SELECT column1, column2
2FROM table_name
3WHERE column_name IN (value1, value2, ...);
- The query will return rows where column_name matches any value listed inside IN().
- This is equivalent to using multiple OR conditions.
2. Using IN
for Genre Filtering
Instead of writing:
1SELECT title, genre
2FROM netflix_series
3WHERE genre = 'Crime' OR genre = 'Sci-Fi';
You can write:
1SELECT title, genre
2FROM netflix_series
3WHERE genre IN ('Crime', 'Sci-Fi');
Output Example:
title | genre |
---|---|
Stranger Things | Sci-Fi |
Dark | Sci-Fi |
Black Mirror | Sci-Fi |
Money Heist | Crime |
Narcos | Crime |
Breaking Bad | Crime |
What’s Happening?
- IN ('Crime', 'Sci-Fi') filters only shows within these genres.
- The query is shorter and easier to read than using multiple OR conditions.
Using IN
with Numeric Values
The IN clause also works for numeric comparisons.
Example Query: Finding Series Released in 2015, 2017, or 2020
1SELECT title, release_year
2FROM netflix_series
3WHERE release_year IN (2015, 2017, 2020);
Output Example:
title | release_year |
---|---|
Narcos | 2015 |
Money Heist | 2017 |
Dark | 2017 |
Bridgerton | 2020 |
What’s Happening?
- The query filters only shows released in the specified years (2015, 2017, 2020).
- Without IN, we would have to write:sqlCopyEditWHERE release_year = 2015 OR release_year = 2017 OR release_year = 2020;
SQL Exercises
Exercise 1: Filtering Netflix Shows by Genre
Alex wants to analyze popular genres. Retrieve all Netflix series that belong to either the “Crime” or “Sci-Fi” genres, sorted alphabetically by title.
Filter condition:
- genre must be ‘Crime’ or ‘Sci-Fi’.
- Sort results by title in ascending order.
Expected Output:
title | genre |
---|---|
Black Mirror | Sci-Fi |
Breaking Bad | Crime |
Dark | Sci-Fi |
Money Heist | Crime |
Narcos | Crime |
Stranger Things | Sci-Fi |
Write an SQL query to return the requested data.
Exercise 2: Finding Shows Released in Specific Years
Alex wants to generate a report showing all series released in 2016, 2017, or 2021, sorted by release_year in ascending order, then title in ascending order.
Filter condition:
- release_year must be 2016, 2017, or 2021.
- Sort by release_year in ascending order, then title in ascending order.
Expected Output:
title | release_year |
---|---|
“Stranger Things” | 2016 |
“The Crown” | 2016 |
“Dark” | 2017 |
“Money Heist” | 2017 |
“Squid Game” | 2021 |
Write an SQL query to return the requested data.