0

I know how the following work

1) select description from mytable where description LIKE "club%" It matches rows where description has club keyword followed by anything e.g. clubbing or club sport

2) select description from mytable where description LIKE "%club" It matches rows where description has club keyword at the end of anything e.g. cricket-club

3) select description from mytable where description LIKE "%club%" It matches rows where description has club keyword anywhere e.g. cricketclubdog

However, I'm working on a piece of code from another developer which uses expression like

select description from mytable where description LIKE "%youth%club%"

Does anyone know what it is supposed to match? I found one answer here at stackoverflow but it doesn't describe much - https://stackoverflow.com/a/9099684/87596

Community
  • 1
  • 1
TigerTiger
  • 95
  • 1
  • 7
  • The `%` wildcard applies in the same way, just between them. So it would match `youth oriented tennis clubs` for example. https://dev.mysql.com/doc/refman/5.0/en/string-comparison-functions.html#operator_like – Michael Berkowski Aug 12 '15 at 15:36
  • % stands for any character or characters,so you do the math – Mihai Aug 12 '15 at 15:37
  • % matches any number of characters, even zero characters. cf [doc](http://dev.mysql.com/doc/refman/5.6/en/string-comparison-functions.html#operator_like) – Meeuuuhhhh Aug 12 '15 at 15:37

2 Answers2

1

% always matches whatever, so %Youth%club% will match any text that has Youth followed by club and there may or may not be something before, in between or after.

For example it would match:

Youthclub
Youth tennis club
Primary Youth club for Texas

but not

club for Youth

Sami Kuhmonen
  • 30,146
  • 9
  • 61
  • 74
0

% is a wildcard - it will match any series of characters, including the empty string. So the query:

select description 
from mytable 
where description LIKE "%youth%club%"

Would return any record where the words "youth" and "club" (in that order) appeared in the description field.

Sculper
  • 756
  • 2
  • 12
  • 24