MySQL SELECT LIKE 或 REGEXP 匹配一条记录中的多个单词 [英] MySQL SELECT LIKE or REGEXP to match multiple words in one record

查看:45
本文介绍了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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆