MySQL SELECT LIKE或REGEXP以在一条记录中匹配多个单词 [英] MySQL SELECT LIKE or REGEXP to match multiple words in one record
本文介绍了MySQL SELECT LIKE或REGEXP以在一条记录中匹配多个单词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
字段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%'
这篇关于MySQL SELECT LIKE或REGEXP以在一条记录中匹配多个单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文