= which matches exact values, LIKE uses wildcards to find partial matches. In this chapter, you will learn how to use the % and _ wildcards to search strings in your database using the WHERE clause.SQL LIKE Syntax
SELECT column1, column2
FROM table_name
WHERE column LIKE 'pattern';
The Two LIKE Wildcards
| Wildcard | Meaning | Example | Matches |
|---|---|---|---|
% |
Zero, one, or many characters | 'M%' |
Mumbai, Marketing, Mike |
_ |
Exactly one character | '_ohn' |
John (not Johnathan) |
You will explore these wildcards in much more detail in Chapter 16: SQL Wildcards. We will use this Employees table:
+----+-----------+------------+--------+-----------+
| ID | Name | Department | Salary | City |
+----+-----------+------------+--------+-----------+
| 1 | Priya K. | Sales | 55000 | Mumbai |
| 2 | John D. | Marketing | 62000 | London |
| 3 | Arun M. | IT | 78000 | Delhi |
| 4 | Emma W. | Sales | 51000 | Sydney |
| 5 | Ravi S. | IT | 72000 | Mumbai |
| 6 | Sara L. | HR | 58000 | New York |
+----+-----------+------------+--------+-----------+
% Wildcard Examples
Names starting with ‘A’:
SELECT Name FROM Employees
WHERE Name LIKE 'A%';
+-----------+ | Name | +-----------+ | Arun M. | +-----------+
Names containing ‘a’:
SELECT Name FROM Employees
WHERE Name LIKE '%a%';
+-----------+ | Name | +-----------+ | Priya K. | | Arun M. | | Emma W. | | Ravi S. | | Sara L. | +-----------+
Cities starting with ‘M’:
SELECT Name, City FROM Employees
WHERE City LIKE 'M%';
+-----------+--------+ | Name | City | +-----------+--------+ | Priya K. | Mumbai | | Ravi S. | Mumbai | +-----------+--------+
Common LIKE Patterns
| Pattern | Meaning |
|---|---|
'A%' |
Starts with A |
'%a' |
Ends with a |
'%an%' |
Contains “an” anywhere |
'_o%' |
Second character is o |
'J___' |
Starts with J, exactly 4 characters total |
'%s' |
Ends with s |
NOT LIKE
Use NOT LIKE to exclude rows matching a pattern. You can combine LIKE with AND, OR, and NOT operators for complex filters:
SELECT Name, Department FROM Employees
WHERE Department NOT LIKE 'S%';
+-----------+------------+ | Name | Department | +-----------+------------+ | John D. | Marketing | | Arun M. | IT | | Ravi S. | IT | | Sara L. | HR | +-----------+------------+
⚠️ Case Sensitivity
LIKE is case-insensitive in MySQL (default) and SQL Server, but case-sensitive in PostgreSQL. In PostgreSQL, use ILIKE for case-insensitive pattern matching.
For a complete reference of pattern matching, see the official MySQL pattern matching documentation. In the next chapter, you will learn advanced SQL Wildcards including escaping and database-specific characters.
If you work with data regularly, explore our ready-made Dashboard Templates on NextGenTemplates that use SQL-powered data for business reporting.
📺 Visit our YouTube channel @NeoTechNavigators for step-by-step video tutorials and dashboard demos on this topic.
🧪 Try It Yourself
Write a query that finds all employees whose name starts with ‘S’ or whose city ends with ‘i’.
SELECT Name, City FROM Employees
WHERE Name LIKE 'S%'
OR City LIKE '%i';
Expected Output:
+-----------+-----------+ | Name | City | +-----------+-----------+ | Priya K. | Mumbai | | Arun M. | Delhi | | Ravi S. | Mumbai | | Sara L. | New York | +-----------+-----------+
📝 What You Learned in This Chapter
LIKEsearches for patterns in text columns%matches zero, one, or many characters_matches exactly one characterNOT LIKEexcludes rows matching a pattern- LIKE is case-insensitive in MySQL, case-sensitive in PostgreSQL
Frequently Asked Questions
% wildcard represents zero, one, or multiple characters. 'M%' matches any string starting with M (Mumbai, Marketing, Mike). '%a%' matches any string containing the letter a anywhere.= matches an exact value. LIKE matches a pattern using wildcards. Use = when you know the exact value, use LIKE when you need partial or pattern-based matching.ILIKE for case-insensitive matching. Check your database settings to be sure.WHERE Name LIKE 'A%' OR Name LIKE 'S%' finds names starting with A or S.=, >, <) for numeric filtering instead.📖 Chapter 15 of 30 — SQL Tutorial on Neotech Navigators



