Searching from comma separated value

后端 未结 5 771
迷失自我
迷失自我 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条回答
  •  情话喂你
    2020-12-21 18:55

    So you're saying you want a query that returns all rows where a user has a specific option?

    Well, ugh...okay, this isn't pretty, but you already know that, so:

    select * from user_table
       where concat(',',option_field,',') like "%,option_you_want,%"
    

    I can't speak to the performance impact--it's likely not pleasant, but I think your other option is to break out the row into a separate table, but you're saying that's not realistically available to you.

提交回复
热议问题