ML Engineer MasterClass (April) | 6 seats left

LIKE

LIKE

Lesson Objectives

By the end of this lesson, you will:

  • Learn how to filter text data using LIKE
  • Understand wildcard characters (% and _) for flexible pattern matching
  • Write SQL queries to find Netflix series based on keyword searches

🎬 Scenario: Finding Shows with “Dark” in the Title

Your manager at Netflix, Alex, is analyzing user interest in dark-themed content.

Alex asks:

Can you retrieve all shows that have the word “Dark” anywhere in the title?

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 Text Data with ‘LIKE’

The LIKE operator allows us to search for patterns in text. Instead of filtering by an exact match (=), we can use wildcard characters:

WildcardDescription
%Represents zero or more characters
_Represents a single character

Syntax:

SQL
SELECT column1, column2  
FROM table_name  
WHERE column_name LIKE 'pattern';

Example Query: Finding Titles Containing “Dark”

SQL
SELECT title, genre, rating  
FROM netflix_series  
WHERE title LIKE '%Dark%';

Expected Output:

titlegenrerating
DarkSci-Fi8.8

What’s Happening?

  • LIKE %Dark% searches for any title that contains the word “Dark” anywhere.
  • The % wildcard allows matches at the beginning, middle, or end of the title.

2. More Pattern Matching Examples

PatternMatchesExample Query
D%Titles that start with “D”WHERE title LIKE D%
%GameTitles that end with “Game”WHERE title LIKE %Game
%Mirror%Titles that contain “Mirror” anywhereWHERE title LIKE %Mirror%
S____ GameTitles that start with “S” and are 11 characters longWHERE title LIKE S____ Game

Example Query: Finding Titles That Start with “S”

SQL
SELECT title, genre  
FROM netflix_series  
WHERE title LIKE 'S%';

Expected Output:

titlegenre
Stranger ThingsSci-Fi
Squid GameThriller

What’s Happening?

  • LIKE S% ensures that only titles starting with “S” appear in the results.

✍️ SQL Exercises

Exercise 1: Finding Netflix Shows with “Game” in the Title

Netflix executives want a list of all series that contain “Game” anywhere in the title.

Filter condition:

  • title must contain the word “Game”.

Expected Output Example:

titlegenrerating
Squid GameThriller8.0

Write an SQL query to return the requested data.


Exercise 2: Finding Shows That Start with “B”

Alex is preparing a new recommendation system and wants to identify all Netflix series whose titles start with “B”. Order the table in the ascending order of rating.

Filter condition:

  • title must start with the letter “B”.

Expected Output Example:

titlegenrerating
BridgertonDrama7.3
Black MirrorSci-Fi8.8
Breaking BadCrime9.5

Write an SQL query to return the requested data.