我如何匹配逗号分隔的字符串与另一个逗号分隔的字符串

时间:2017-11-08 10:59:22

标签: php mysql sql database

我希望在match中以string 2个逗号分隔mysql

test string => Housekeeping,Cleaning,Other

|              skills                 |
+-------------------------------------+
|    Housekeeping,Cleaning,Sweeping   |
+-------------------------------------+
|  Housewives,Beautician,Cleaning     |        AGAINST  `Housekeeping,Cleaning,Other`
+-------------------------------------+
|        PHP,Laravel,Other            |
+-------------------------------------+
|   Housekeeping,housekeeping,other   |
+-------------------------------------+


MUST MATCH  =>  All the `rows`

我听说过LOCATE语法,但不知道如何使用。

SELECT * FROM jobs_posted_by_employer WHERE skills [don't know]

我保留了table 在线以查询execution !!!

这是我的查询http://sqlfiddle.com/#!9/b1931

1 个答案:

答案 0 :(得分:2)

使用regexp(你需要用PHP重新格式化你的输入):http://sqlfiddle.com/#!9/b1931/13

select
    *
from
    jobs_posted_by_employer
where
    skills regexp '(^|,)Housekeeping|Cleaning|Other(,|$)'

或没有PHP重新格式化:http://sqlfiddle.com/#!9/b1931/40

select
    *
from
    jobs_posted_by_employer
where
    skills  regexp concat(
        '(^|,)',
        replace('Housekeeping,Cleaning,Other',',','|'),
        '(,|$)'
    )
相关问题