Logical AND operator in mySql REGEXP?

前端 未结 5 1629
名媛妹妹
名媛妹妹 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:32

    You can add several conditions with AND between them:

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

    Maybe REGEXP is not necessary here and you may use INSTR instead (regular are usually slower):

    SELECT * FROM myTable
    WHERE INSTR(title, "dog") AND INSTR(title, "cat") AND INSTR(title, "mouse");
    

提交回复
热议问题