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 匹配一条记录中的多个单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:MySQL SELECT LIKE 或 REGEXP 匹配一条记录中的多个单词


基础教程推荐
- 无法在 ubuntu 中启动 mysql 服务器 2021-01-01
- SQL Server 2016更改对象所有者 2022-01-01
- SQL Server 中单行 MERGE/upsert 的语法 2021-01-01
- 在 VB.NET 中更新 SQL Server DateTime 列 2021-01-01
- ERROR 2006 (HY000): MySQL 服务器已经消失 2021-01-01
- SQL Server:只有 GROUP BY 中的最后一个条目 2021-01-01
- Sql Server 字符串到日期的转换 2021-01-01
- 将数据从 MS SQL 迁移到 PostgreSQL? 2022-01-01
- 使用pyodbc“不安全"的Python多处理和数据库访问? 2022-01-01
- 如何在 SQL Server 的嵌套过程中处理事务? 2021-01-01