LIKE is an SQL operator for performing string comparisons with pattern matching in (relational) databases. Example:

SELECT nickname, firstname, lastname FROM example WHERE firstname LIKE 'Jo%'

The statement above will return all rows where the string in the field firstname begins with Jo.

The syntax is <expression> LIKE <pattern>. <expression> is the value to be compared with the <pattern>. Here are some rules for the pattern matching:

  • Any normal characters in pattern must match exactly, case sensitively.
  • % (percent) matches any sequence of zero ore more characters. For example, the pattern 'a%c' matches 'abbc' and 'ac' but not 'bbc'.
  • _ (underscore) matches exactly one character. For example, the pattern 'a_c' matches 'abc' and 'a0c' but not 'abcd'.
  • If the expression is NULL, then no pattern will match it, not even %.

There are additional characters that can be used in the pattern on some database servers. Those listed above should work on almost any server, for example Oracle and Microsoft SQL Server.