Pattern Matching in Search Conditions

Use the LIKE operator in a WHERE clause to search for patterns in a column.

Listing Specific Employees

To list all employees whose surname begins with "br" type the following:

SELECT Surname, GivenName
FROM Employees
WHERE Surname LIKE 'br%'

Surname

GivenName

Breault

Robert

Braun

Jane

The % in the search condition indicates that any number of other characters may follow the letters BR.

Qualifying the Surname Search

To list all employees whose surname begins with BR, followed by zero or more letters and a T, followed by zero or more letters, type:

SELECT Surname, GivenName
FROM Employees
WHERE Surname LIKE 'BR%T%'

Surname

GivenName

Breault

Robert

The first % sign matches the string “eaul”, and the second % sign matches the empty string (no characters).

Another special character that can be used with LIKE is the _ (underscore) character, which matches exactly one character.

The pattern BR_U% matches all names starting with BR and having U as the fourth letter. In Braun, the _ matches the letter A, and the % matches N.