LIKE – Match Text Patterns in SQL

🔧 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 email city
1Fenn Raskfenn@email.comFogtown
2Milo Kreshmilo@dustmail.netDustvale
3Sora Dunesora_dune@gmail.comCloudhill
4Tovi Glintt.glint@windmail.netWindmere
5Lexa Vohnlexa.vohn@gmail.comFogtown
6Kye Trinnkye@dustmail.netDustvale

✅ 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

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top