mySql REGEXP中的逻辑AND运算符? [英] Logical AND operator in mySql REGEXP?

查看:122
本文介绍了mySql REGEXP中的逻辑AND运算符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用MySql REGEXP:

I use MySql REGEXP:

SELECT * FROM myTable
WHERE title REGEXP "dog|cat|mouse";

数据集很小,因此我不关心性能.而且我更喜欢LIKE表示法,因为我不必连接一堆"LIKE"语句.

The dataset is small, so I am not concerned about performance. And I prefer this over LIKE notation, because I do not have to concatenate a bunch of "LIKE" statements.

但是,以上表示法使用逻辑OR运算符.是否存在逻辑AND运算符,以便仅匹配包含所有关键字的行?

However, the above notation uses a logical OR operator. Is there a logical AND operator, so that only rows containing all of the keywords are matched?

(我使用的是InnoDB,因此无法进行全文搜索)

(I am using InnoDB so fulltext search not an option)

推荐答案

除了串联AND,真的没有什么好办法了:

There's really no nice solution except concatenating ANDs:

SELECT * FROM myTable
WHERE title REGEXP "dog"
AND title REGEXP "cat"
AND title REGEXP "mouse"

否则,正则表达式将如下所示:

The regular expression would otherwise look like this:

SELECT * FROM myTable
WHERE title REGEXP "(dog.*cat.*mouse)|(dog.*mouse.*cat)|(mouse.*dog.*cat)|(mouse.*cat.*dog)|(cat.*dog.*mouse)|(cat.*mouse.*dog)"

这篇关于mySql REGEXP中的逻辑AND运算符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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