MySQL: LIKE Condition
This MySQL LIKE operator checks and explains how to use the MySQL LIKE condition to perform specified character string pattern matching with syntax and examples.
The MySQL LIKE condition allows wildcards to be used in the WHERE clause of a SELECT, INSERT, UPDATE, or DELETE statement. This allows you to perform pattern matching.
The syntax for the LIKE Condition in MySQL is:
MySQL provides two wildcard characters for using with the LIKE operator, the percentage % and underscore _ .
- The percentage ( % ) wildcard allows you to match any string of zero or more characters.
- The underscore ( _ ) wildcard allows you to match any single character.
MySQL LIKE examples
Let’s practice with some examples of using the LIKE operator. See the following employee table.
MySQL LIKE with percentage (%) wildcard
Suppose you want to search for employee whose first name starts with character a, you can use the percentage wildcard ( % ) at the end of the pattern as follows:
MySQL LIKE with underscore( _ ) wildcard
To find employee whose first name starts with T, ends with m and contains any single character between e.g., Tom , Tim, you use the underscore wildcard to construct the pattern as follows:
MySQL LIKE operator with NOT operator
The MySQL allows you to combine the NOT operator with the LIKE operator to find a string that does not match a specific pattern.
–> In this tutorial, you have learned how to use the LIKE operator to query data based on patterns, which is more flexible than using comparison operators.