Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how do i match comma separated string with another comma separated string

i want to match 2 comma separated string in 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`

i heard about LOCATE syntax but don't know to use.

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

i have kept my table online for query execution!!!

here is my Query:http://sqlfiddle.com/#!9/b1931

like image 201
arjun_web Avatar asked Feb 26 '26 12:02

arjun_web


1 Answers

Using regexp (you need reformat a little your input with PHP) : http://sqlfiddle.com/#!9/b1931/13

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

or without PHP reformat : http://sqlfiddle.com/#!9/b1931/40

select
    *
from
    jobs_posted_by_employer
where
    skills  regexp concat(
        '(^|,)',
        replace('Housekeeping,Cleaning,Other',',','|'),
        '(,|$)'
    )
like image 106
Indent Avatar answered Feb 28 '26 00:02

Indent



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!