WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

SQL LIKE Operator


The LIKE operator keyword is useful when specifying a search condition within your WHERE clause.


The SQL LIKE Operator

The LIKE operator keyword is useful when specifying a search condition within your WHERE clause.

SQL LIKE Syntax

SELECT column_name(s)
FROM table_name
WHERE column_name LIKE pattern;

Database

In this tutorial we can use the well-known database.

Below is a selection from the "Customers" table:

CustomerID FirstName Phone Username Password Email address
1

Roy K. Berry (03) 5379 4852 Thatiow ieV4Aitah RoyKBerry@dayrep.com
2 Josie J. Futrell (02) 4032 7368 Mdlisives40 ozuchaz7Ei JosieJFutrell@dayrep.com
3 James C. Walters (02) 4063 7155 Sincy1945 eer6Ooghie JamesCWalters@rhyta.com
4

Norma A. Jimenez (03) 5333 5321 Gode1942 Jeeh1rahPh NormaAJimenez@dayrep.com
5 Andrea J. Farmer (02) 9234 0059 Saydrund chai3Geel AndreaJFarmer@teleworm.us

SQL LIKE Operator Examples

The following SQL statement selects all customers with a Email address starting with the letter "e":

Example

SELECT * FROM Customers
WHERE Email LIKE 'e%';

Tip: The "%" sign is used to define wildcards  both before and after the pattern. "%" to match an arbitrary number of characters (including zero characters). in the next chapter.

The following SQL statement selects all customers with a Email ending with the letter "e":

Example

SELECT * FROM Customers
WHERE Email LIKE '%e';

The following SQL statement selects all customers with a Country containing the pattern "Better":

Example

SELECT * FROM Customers
WHERE Country LIKE '%Better%';

Using the NOT keyword allows you to select records that do NOT match the pattern.

The following SQL statement selects all customers with Password NOT containing the pattern "user":

Example

SELECT * FROM Customers
WHERE Password NOT LIKE '%user%';

The % wildcard can be used multiple times within the same pattern.