MySQL喜欢whitespace通配符

时间:2014-07-09 19:57:56

标签: mysql sql wildcard sql-like

所以我遇到了一个问题,当我在字符串中有空格时,我想搜索空格是条约作为通配符(或者,或者,我不确定哪个;无论如何;它不是空白的。)

例如,让我们说我正在寻找约翰史密斯'。

Select name from people where name like '%John Smith%'

现在我想要归还的是

Dr. John Smith
John Smith Jr.
John Smith IV

但我遇到的是混合(上述结果和下面的内容)

John Williams Smith
John Ron Smith
John J. Smith

我不在乎其他数据,我正在寻找那个确切的字符串" John Smith"以及它左边或右边的任何东西。

感谢您的任何建议。

1 个答案:

答案 0 :(得分:0)

(显然我还不能发表评论)

我很好奇,如果你使用REGEX,你会得到正确的结果吗?

select name 
from people 
where name REGEXP  '[:alpha]*JOHN SMITH[:alpha]*'