So far you've filtered data using exact matches with WHERE clauses. But what if you want to find all customers whose names start with "John" but might be "Johnson", "Johnston", or "Johnny"?
Exact matching with = won't work here. You need flexible pattern matching.
Engagement Message
Can you think of other situations where exact matching would be too restrictive?
The LIKE operator lets you search for patterns instead of exact matches. It's perfect for partial text searches.
Instead of WHERE name = 'John'
, you can use WHERE name LIKE 'John%'
to find names starting with "John".
Engagement Message
What's one example where you'd use LIKE instead of =?
The % wildcard represents any number of characters (including zero). Think of it as "anything can go here."
SELECT name FROM customers WHERE email LIKE '%@gmail.com';
This finds all Gmail users regardless of what comes before the @.
Engagement Message
What would LIKE 'A%'
find in a names column?
The _ wildcard represents exactly one character. It's more precise than %.
SELECT product FROM inventory WHERE code LIKE 'PR_001';
This matches PR1001, PRA001, PRB001, but NOT PRA2001 (too many characters).
Engagement Message
When would you use _ instead of %?
