The LIKE operator is used in a WHERE clause to search for a specific pattern in a column.
👉 It is mainly used with text (string) data.
SELECT column_name
FROM table_name
WHERE column_name LIKE pattern;
| Wildcard | Meaning |
|---|---|
% |
Represents zero or more characters |
_ |
Represents exactly one character |
| ID | Name |
|---|---|
| 1 | Amit |
| 2 | Riya |
| 3 | Rahul |
| 4 | Neha |
| 5 | Karan |
% (Multiple Characters)SELECT * FROM Students
WHERE Name LIKE 'A%';
Returns names that start with 'A'.
SELECT * FROM Students
WHERE Name LIKE '%a';
Returns names that end with 'a'.
SELECT * FROM Students
WHERE Name LIKE '%h%';
Returns names that contain 'h' anywhere.
_ (Single Character)SELECT * FROM Students
WHERE Name LIKE '_i%';
iSELECT * FROM Students
WHERE Name LIKE '____';
Used to exclude patterns.
SELECT * FROM table_name
WHERE column_name NOT LIKE pattern;
SELECT * FROM Students
WHERE Name NOT LIKE 'A%';
Returns names that do not start with 'A'.
LIKE as case-insensitive.Age LIKE '2%' -- Not recommended for numeric columns
SELECT * FROM Students
WHERE Name LIKE 'R%' AND Age > 18;
| Operator | Purpose |
|---|---|
| = | Exact match |
| IN | Match from list |
| BETWEEN | Range |
| LIKE | Pattern matching |
The LIKE operator is essential when: