Searching from comma separated value

后端 未结 5 772
迷失自我
迷失自我 2020-12-21 18:01

This is one of those \'oh my god\' moments.

The previous programmer in our company has left behind a badly-coded application using PHP and MySQL.

One example

5条回答
  •  -上瘾入骨i
    2020-12-21 18:52

    You could use FIND_IN_SET to retrieve rows that match your criteria:

    SELECT * FROM your_table WHERE FIND_IN_SET('value', field_with_comma_sep_values) > 0;
    

    Basically, FIND_IN_SET returns the index of the found item. So this query finds all rows where it finds the matching word in the "set" of comma separated values.

    Credit: I knew there was something like this, but this post is where I found the answer and the SELECT statement.

提交回复
热议问题