string LIKE pattern [ESCAPE escape_character]

Description: Looks for pattern within string, performing a pattern-match comparison using SQL simple regular expressions, returning TRUE if a match is obtained or FALSE if not.

pattern may contain wildcard characters:

  • %— For matching any number of characters of string, including none

  • _ (underscore)— For matching exactly one character

To match on the % and _ characters themselves, they will need to be preceded by an escape character. This is \ by default, unless otherwise specified by escape_character.

Examples:

  • 'Jonathan' LIKE 'Jon%' returns 1.

  • 'Jonathan' LIKE 'JON%' returns 1.

  • 'Jonathan' LIKE BINARY 'JON%' returns 0.

  • 'Jonathan' LIKE 'J%n' returns 1.

  • 'Jonathan' LIKE 'Jo%nathan' returns 1.

  • 'John Smith' ...

Get Sams Teach Yourself MySQL in 21 Days, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.