Professional Documents
Culture Documents
Learning Objectives
At the end of the session, you will be able to use and execute:
Character
String
.
Presentation of Content
The LIKE operator is used in a WHERE clause to search for a specified pattern in a
column.
There are two wildcards often used in conjunction with the LIKE operator:
• The percent sign and the underscore can also be used in combinations!
LIKE Syntax
• 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 characters in
length
WHERE CustomerName LIKE 'a_ _%' Finds any values that start with "a" and are at least 3 characters in
length
WHERE ContactName LIKE 'a%o' Finds any values that start with "a" and ends with "o"
Demo Database
2
Module in Advanced Database Management. For validation and evaluation purposes.
Dexter P. Dumayag, CICS Faculty Member. First Semester, SY 2020-2021
Advanced Database System
The following SQL statement selects all customers with a Name starting with "a":
Example
The following SQL statement selects all receivers with a Name ending with "s":
Example
The following SQL statement selects all receivers with a Name that have "er" in any
position:
3
Module in Advanced Database Management. For validation and evaluation purposes.
Dexter P. Dumayag, CICS Faculty Member. First Semester, SY 2020-2021
Advanced Database System
The following SQL statement selects all receivers with a Name that have "o" in the
second position:
The following SQL statement selects all receivers with a Name that starts with "J" and are
at least 3 characters in length:
Example
The following SQL statement selects all receivers with a Name that starts with "b" and
ends with "s":
Example
4
Module in Advanced Database Management. For validation and evaluation purposes.
Dexter P. Dumayag, CICS Faculty Member. First Semester, SY 2020-2021
Advanced Database System
The following SQL statement selects all receivers with a Name that does NOT start with
"J":
Example
The following SQL statement selects all receivers with a Name that start with "c" and at
least 3 characters:
Example
5
Module in Advanced Database Management. For validation and evaluation purposes.
Dexter P. Dumayag, CICS Faculty Member. First Semester, SY 2020-2021
Advanced Database System
Summary Unit
The LIKE operator is used in a WHERE clause to search for a specified pattern in a column.
There are two wildcards often used in conjunction with the LIKE operator: the percent
sign (%) represents zero, one, or multiple characters and the underscore sign (_)
represents one, single character.
6
Module in Advanced Database Management. For validation and evaluation purposes.
Dexter P. Dumayag, CICS Faculty Member. First Semester, SY 2020-2021
Advanced Database System
References
7
Module in Advanced Database Management. For validation and evaluation purposes.
Dexter P. Dumayag, CICS Faculty Member. First Semester, SY 2020-2021