Filtering Text with LIKE and Wildcards
You'll learn how to search for text patterns in SQL using the LIKE operator and wildcard characters to match partial or flexible text values.
The Core Idea
Sometimes you don't need an exact match when filtering text—you want to find all customers whose names start with "A", or all products containing the word "Pro" anywhere in their description. The LIKE operator lets you match patterns rather than exact strings.
SQL provides two essential wildcard characters:
%(percent sign): Matches any number of characters (zero or more)_(underscore): Matches exactly one character
Think of % like a flexible rubber band that can stretch to fit any amount of text, while _ is a single blank space that must be filled by one character.
How It Works
You use LIKE in the WHERE clause just like the comparison operators you've learned:
SELECT product_name
FROM products
WHERE product_name LIKE 'A%';
This finds all products starting with "A" (Apple, Avocado, Anchovy, etc.).
SELECT email
FROM customers
WHERE email LIKE '%@gmail.com';
This finds all Gmail addresses (the % matches everything before @gmail.com).
SELECT code
FROM products
WHERE code LIKE 'PRO__5';
This matches codes like "PRO125" or "PROX45" where the two underscores require exactly two characters between "PRO" and "5".
Combining Wildcards
You can use multiple wildcards together: LIKE '%manager%' finds "manager", "Senior Manager", or "Assistant Manager" anywhere in a job title.
Key Takeaway: Use LIKE with % to match any sequence of characters and _ to match exactly one character, enabling flexible pattern-based text filtering in SQL queries.