totn Access

MS Access 2007: LIKE condition (using wildcards)

This MSAccess tutorial explains how to create a query using the LIKE condition with wildcards in Access 2007 (with screenshots and step-by-step instructions).

The LIKE condition allows you to use wildcards in the where clause of a SQL statement in Access 2007. This allows you to perform pattern matching. The LIKE condition can be used in any valid SQL statement - select, insert, update, or delete.

The patterns that you can choose from are:

Wildcard Explanation
* Allows you to match any string of any length (including zero length)
? Allows you to match on a single character
# Allows you to match on a single numeric digit

Example

Like 'm*'
Result: all values that start with m

Like '*m*'
Result: all values that contain m

Like '*m'
Result: all values that end with m

Like 'm?'
Result: all values that start with m and are 2 characters in length

Like 'm#'
Result: all values that start with m and are 2 characters in length where the second character is a number

Here is an example of how you'd use the LIKE condition in a query:

Microsoft Access

In this example, we are looking for all employee last names that start with "m".

Combining the LIKE condition with the NOT operator

You can also combine the LIKE condition with the NOT operator.

Example

Not Like 'm*'
Result: all values that do not start with m

Not Like '*m*'
Result: all values that do not contain m

Not Like '*m'
Result: all values that do not end with m

Not Like 'm?'
Result: all values that are not 2 characters in length starting with m

Not Like 'm#'
Result: all values that are not 2 characters in length that start m and where the second character is a number

Here is an example of how you'd use the NOT LIKE condition in a query:

Microsoft Access

In this example, we are looking for all employee last names that do not start with "m".