🔧 Quick Syntax
SELECT column1, column2
FROM table_name
WHERE column_name LIKE 'pattern';
This tells SQL:
“Find rows where this column matches the pattern I give you.”
Wildcard characters:
%
= any number of characters (including none)_
= exactly one character
🧾 Here’s the Table You’re Working With
You’ve got a customers
table:
id | name | city | |
---|---|---|---|
1 | Fenn Rask | fenn@email.com | Fogtown |
2 | Milo Kresh | milo@dustmail.net | Dustvale |
3 | Sora Dune | sora_dune@gmail.com | Cloudhill |
4 | Tovi Glint | t.glint@windmail.net | Windmere |
5 | Lexa Vohn | lexa.vohn@gmail.com | Fogtown |
6 | Kye Trinn | kye@dustmail.net | Dustvale |
✅ Suppose You Want Emails That End with “@gmail.com”
SELECT name, email
FROM customers
WHERE email LIKE '%@gmail.com';
💡 Output:
Sora Dune sora_dune@gmail.com
Lexa Vohn lexa.vohn@gmail.com
The %
means “anything can come before.” SQL finds any email that ends with @gmail.com
.
✅ Suppose You Want Names That Start with “M”
SELECT name
FROM customers
WHERE name LIKE 'M%';
💡 Output:
Milo Kresh
The %
means “anything can come after.” You’re matching names that start with M.
✅ Suppose You Want Cities That Contain “dust”
SELECT city
FROM customers
WHERE city LIKE '%dust%';
💡 Output:
Dustvale
This finds any city that has “dust” anywhere in the name — beginning, middle, or end.
✅ Suppose You Want Emails Where One Character Is a Wildcard
You’re trying to match something like t_glint@...
(underscore used as a wildcard).
SELECT name, email
FROM customers
WHERE email LIKE 't_glint@%';
This would match if the email had exactly one character (like a dot or underscore) between t
and glint
. In this case, it wouldn’t match anything, but it shows how _
works.
🧃 Recap – What You Learned
LIKE
is for matching patterns in text%
matches any number of characters_
matches one single character- Great for names, emails, domains, cities, etc.
- Cleaner than
=
when you want partial or fuzzy matches