Logical AND operator in mySql REGEXP?

前端 未结 5 1636
名媛妹妹
名媛妹妹 2020-12-17 19:28

I use MySql REGEXP:

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

The dataset is small, so I am not concerned about performan

5条回答
  •  盖世英雄少女心
    2020-12-17 19:52

    If your title contains all the search terms, for example:

    Anything mouse anything cat anything dog anything

    Then you will have all the search terms in a three times repeated title in any order (for example dog, cat and mouse).

    Anything mouse anything cat anything DOG anything

    Anything mouse anything CAT anything dog anything

    Anything MOUSE anything cat anything dog anything

    So you can do this without concatenating ANDs with:

    SELECT * FROM myTable WHERE REPEAT(title,3) RLIKE '.*dog.*cat.*mouse.*';

提交回复
热议问题