MySQL SELECT LIKE 或 REGEXP 匹配一条记录中的多个单词

2021-11-20 00:00:00 regex sql-like select mysql

字段table.name 包含'Stylus Photo 2100' 和以下查询

The field table.name contains 'Stylus Photo 2100' and with the following query

SELECT `name` FROM `table` WHERE `name` LIKE '%Stylus 2100%'

我没有得到任何结果.当然,如果我搜索了

I get no results. Of course i would if i searched

SELECT `name` FROM `table` WHERE `name` LIKE '%Photo 2100%'

如何通过搜索Stylus 2100"来选择记录?

How can I select the record by searching 'Stylus 2100' ?

谢谢

推荐答案

好吧,如果您知道单词的顺序.. 您可以使用:

Well if you know the order of your words.. you can use:

SELECT `name` FROM `table` WHERE `name` REGEXP 'Stylus.+2100'

你也可以使用:

SELECT `name` FROM `table` WHERE `name` LIKE '%Stylus%' AND `name` LIKE '%2100%'

相关文章