SQL Like
On this page
SQL LIKE Operator
The LIKE operator is used in a WHERE clause to search for patterns in text columns.
Basic Syntax
SELECT column1 FROM table_name WHERE column1 LIKE pattern;
Wildcard Characters
- % – represents zero, one, or multiple characters
- _ – represents a single character
Starts With
Find names that start with the letter A:
SELECT name FROM customers WHERE name LIKE 'A%';
Ends With
Find emails that end with example.com:
SELECT email FROM customers WHERE email LIKE '%example.com';
Contains
Find products that contain the word phone:
SELECT name FROM products WHERE name LIKE '%phone%';
Single Character Wildcard
Find names with exactly five letters starting with A:
SELECT name FROM customers WHERE name LIKE 'A____';
Using NOT LIKE
Exclude rows that match a pattern:
SELECT name FROM customers WHERE name NOT LIKE 'A%';
Case Sensitivity
Case sensitivity depends on the database collation. In many MySQL configurations, LIKE is case-insensitive by default.
Performance Note
Using LIKE with a leading wildcard (for example, '%phone') can prevent the use of indexes and slow down queries on large tables.
Next Step
Continue with SQL Wildcards for a deeper look at pattern matching rules.