The SQL LIKE Operator
The SQL LIKE Operator
LIKE Operator
❮ PreviousNext ❯
Note: MS Access uses an asterisk (*) instead of the percent sign (%), and a
question mark (?) instead of the underscore (_).
The percent sign and the underscore can also be used in combinations!
LIKE Syntax
SELECT column1, column2, ...
FROM table_name
WHERE columnN LIKE pattern;
Tip: You can also combine any number of conditions using AND or OR operators.
Here are some examples showing different LIKE operators with '%' and '_'
wildcards:
WHERE CustomerName LIKE 'a%' Finds any values that start with "a"
WHERE CustomerName LIKE '%a' Finds any values that end with "a"
WHERE CustomerName LIKE '%or%' Finds any values that have "or" in any position
WHERE CustomerName LIKE '_r%' Finds any values that have "r" in the second position
WHERE CustomerName LIKE 'a_%' Finds any values that start with "a" and are at least 2 character
WHERE CustomerName LIKE 'a__%' Finds any values that start with "a" and are at least 3 character
WHERE ContactName LIKE 'a%o' Finds any values that start with "a" and ends with "o"
Demo Database
The table below shows the complete "Customers" table from the Northwind
sample database:
4 Around the Horn Thomas Hardy 120 Hanover Sq. London WA1
12 Cactus Comidas para Patricio Simpson Cerrito 333 Buenos Aires 1010
llevar
13 Centro comercial Francisco Chang Sierras de Granada 9993 México D.F. 0502
Moctezuma
15 Comércio Mineiro Pedro Afonso Av. dos Lusíadas, 23 São Paulo 0543
18 Du monde entier Janine Labrune 67, rue des Cinquante Nantes 4400
Otages
32 Great Lakes Food Howard Snyder 2732 Baker Blvd. Eugene 9740
Market
36 Hungry Coyote Yoshi Latimer City Center Plaza 516 Elgin 9782
Import Store Main St.
43 Lazy K Kountry Store John Steel 12 Orchestra Terrace Walla Walla 9936
45 Let's Stop N Shop Jaime Yorres 87 Polk St. Suite 5 San 9411
Francisco
54 Océano Atlántico Yvonne Moncada Ing. Gustavo Moncada Buenos Aires 1010
Ltda. 8585 Piso 20-A
58 Pericles Comidas Guillermo Calle Dr. Jorge Cash 321 México D.F. 0503
clásicas Fernández
62 Queen Cozinha Lúcia Carvalho Alameda dos Canàrios, São Paulo 0548
891
64 Rancho grande Sergio Gutiérrez Av. del Libertador 900 Buenos Aires 1010
75 Split Rail Beer & Ale Art P.O. Box 555 Lander 8252
Braunschweiger
78 The Cracker Box Liu Wong 55 Grizzly Peak Rd. Butte 5980
80 Tortuga Restaurante Miguel Angel Avda. Azteca 123 México D.F. 0503
Paolino
82 Trail's Head Gourmet Helvetius Nagy 722 DaVinci Blvd. Kirkland 9803
Provisioners
89 White Clover Markets Karl Jablonski 305 - 14th Ave. S. Suite Seattle 9812
3B
Example
SELECT * FROM Customers
WHERE CustomerName LIKE 'a%';
Try it Yourself »
The following SQL statement selects all customers with a CustomerName ending
with "a":
Example
SELECT * FROM Customers
WHERE CustomerName LIKE '%a';
Try it Yourself »
The following SQL statement selects all customers with a CustomerName that
have "or" in any position:
Example
SELECT * FROM Customers
WHERE CustomerName LIKE '%or%';
Try it Yourself »
The following SQL statement selects all customers with a CustomerName that
have "r" in the second position:
Example
SELECT * FROM Customers
WHERE CustomerName LIKE '_r%';
Try it Yourself »
The following SQL statement selects all customers with a CustomerName that
starts with "a" and are at least 3 characters in length:
Example
SELECT * FROM Customers
WHERE CustomerName LIKE 'a__%';
Try it Yourself »
The following SQL statement selects all customers with a ContactName that
starts with "a" and ends with "o":
Example
SELECT * FROM Customers
WHERE ContactName LIKE 'a%o';
Try it Yourself »
The following SQL statement selects all customers with a CustomerName that
does NOT start with "a":
Example
SELECT * FROM Customers
WHERE CustomerName NOT LIKE 'a%';
Try it Yourself »
Submit Answer »
❮ PreviousNext ❯
COLOR PICKER
LIKE US
Get certified
by completing
a course today!
w3schoolsCERTIFIED.2021
Get started
CODE GAME
Play Game
REPORT ERROR
FORUM
ABOUT
SHOP
Top Tutorials
HTML Tutorial
CSS Tutorial
JavaScript Tutorial
How To Tutorial
SQL Tutorial
Python Tutorial
W3.CSS Tutorial
Bootstrap Tutorial
PHP Tutorial
Java Tutorial
C++ Tutorial
jQuery Tutorial
Top References
HTML Reference
CSS Reference
JavaScript Reference
SQL Reference
Python Reference
W3.CSS Reference
Bootstrap Reference
PHP Reference
HTML Colors
Java Reference
Angular Reference
jQuery Reference
Top Examples
HTML Examples
CSS Examples
JavaScript Examples
How To Examples
SQL Examples
Python Examples
W3.CSS Examples
Bootstrap Examples
PHP Examples
Java Examples
XML Examples
jQuery Examples
Web Courses
HTML Course
CSS Course
JavaScript Course
Front End Course
SQL Course
Python Course
PHP Course
jQuery Course
Java Course
C++ Course
C# Course
XML Course
Get Certified »