like

description

syntax

BOOLEAN like(VARCHAR str, VARCHAR pattern)

Perform fuzzy matching on the string str, return true if it matches, and false if it doesn’t match.

like match/fuzzy match, will be used in combination with % and _.

the percent sign (‘%’) represents zero, one, or more characters.

the underscore (‘_‘) represents a single character.

  1. 'a' // Precise matching, the same effect as `=`
  2. '%a' // data ending with a
  3. 'a%' // data starting with a
  4. '%a%' // data containing a
  5. '_a_' // three digits and the middle letter is a
  6. '_a' // two digits and the ending letter is a
  7. 'a_' // two digits and the initial letter is a
  8. 'a__b' // four digits, starting letter is a and ending letter is b

example

  1. // table test
  2. +-------+
  3. | k1 |
  4. +-------+
  5. | b |
  6. | bb |
  7. | bab |
  8. | a |
  9. +-------+
  10. // Return the data containing a in the k1 string
  11. mysql> select k1 from test where k1 like '%a%';
  12. +-------+
  13. | k1 |
  14. +-------+
  15. | a |
  16. | bab |
  17. +-------+
  18. // Return the data equal to a in the k1 string
  19. mysql> select k1 from test where k1 like 'a';
  20. +-------+
  21. | k1 |
  22. +-------+
  23. | a |
  24. +-------+

keyword

LIKE