🔍 SQL LIKE Operator – Search with Wildcards Like a Pro
Want to filter data based on patterns instead of exact values?
The SQLLIKEoperator helps you find text that matches a specific pattern, not just an exact match.
It’s perfect for partial searches, email filtering, name lookups, and more.
📌 What is SQL LIKE?
The SQL LIKE operator is used in a WHERE clause to search for a specified pattern in a column.
It is commonly used with:
%(percent) – represents zero, one, or many characters_(underscore) – represents a single character
🧾 SQL LIKE Syntax
SELECT column1, column2, ...
FROM table_name
WHERE column_name LIKE pattern;
Wildcard patterns:
| Pattern | Meaning |
|---|---|
'A%' | Starts with A |
'%Z' | Ends with Z |
'%ice%' | Contains “ice” |
'_at' | Matches “cat”, “bat”, “hat”, etc. |
'M___' | Starts with M and is exactly 4 characters |
✅ Example 1: Find Names That Start with ‘S’
SELECT first_name
FROM employees
WHERE first_name LIKE 'S%';
🧠 Matches: Sam, Steve, Shubham
✅ Example 2: Find Products Ending with “Pro”
SELECT product_name
FROM products
WHERE product_name LIKE '%Pro';
✅ Matches: iPhone Pro, Galaxy Pro, Surface Pro
✅ Example 3: Emails That Contain “edu”
SELECT email
FROM users
WHERE email LIKE '%edu%';
🎯 Finds all emails containing “edu” (e.g., .edu domains)
✅ Example 4: Match Exact Character Patterns
SELECT code
FROM coupons
WHERE code LIKE 'A_3';
🧩 This matches codes like “AB3”, “AC3”, but not “A33” or “A3”
🚫 Use NOT LIKE to Exclude Patterns
SELECT username
FROM users
WHERE username NOT LIKE 'admin%';
This query excludes usernames that begin with “admin”.
💡 Tips for Using LIKE
- Use
LOWER()orUPPER()for case-insensitive searches (some databases are case-sensitive by default).WHERE LOWER(name) LIKE 'john%' - Avoid leading
%when possible – it’s less performant as it prevents index use.
🧪 Practice Challenge
Task: Find customer names that contain “raj” anywhere in the name.
SELECT customer_name
FROM customers
WHERE customer_name LIKE '%raj%';
📝 Final Thoughts
The LIKE operator is a must-have tool for:
✅ Flexible search queries
✅ Pattern-based filtering
✅ Dynamic user input search
Use it with wildcards (%, _) to perform powerful text searches—across names, emails, product codes, and more.

