How to Use LIKE Operator in SQL

The LIKE operator is used in a WHERE clause to search for a specified pattern in a column. There are two wildcards used in conjunction with the LIKE operator.

images/articles/mysql/use-like-operar-in-sql.jpg
  1. % : The percent sign represents zero, one, or more characters.
  2. _ : The underscore represents a single character.

A wildcard character is used to substitute any other character or characters in a string.

The percent sign and the underscore can also be used in combinations. You can also combine any number of conditions using AND or OR operators.

Examples

1. Find values that starts with "a"

a%

2. Find values that ends with "a"

a%

3. Find values that have "word" in any position

%word%

4. Find values that have "m" in the second position

_m%

5. Find values that starts with "a" and ends with "n"

a%n