ASA Getting Started
Selecting Data from Database Tables
Selecting rows from a table
Pattern matching is a versatile way of identifying character data. In SQL, the LIKE keyword is used to search for patterns. Pattern matching employs wildcard characters to match different combinations of characters.
List all employees whose last name begins with BR
In Interactive SQL, type the following in the SQL Statements pane:
SELECT emp_lname, emp_fname FROM employee WHERE emp_lname LIKE 'br%'
emp_lname | emp_fname |
---|---|
Breault | Robert |
Braun | Jane |
The % in the search condition indicates that any number of other characters may follow the letters BR
.
List all employees whose last name begins with BR, followed by zero or more letters and a T, followed by zero or more letters
In Interactive SQL, type the following in the SQL Statements pane:
SELECT emp_lname, emp_fname FROM employee WHERE emp_lname LIKE 'BR%T%'
emp_lname | emp_fname |
---|---|
Breault | Robert |
The first % sign matches the string eaul, while 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. For example, the pattern 'BR_U%'
matches all names starting with BR
and having U
as the fourth letter. In Braun
the _
character matches the letter A
and the %
matches N
.
For more information, see LIKE conditions.