MySQL query finding values in a comma separated string

后端 未结 11 1421
孤独总比滥情好
孤独总比滥情好 2020-11-21 23:40

I have a field COLORS (varchar(50)) in a my table SHIRTS that contains a comma delimited string such as 1,2,5,12,15,. Each number repr

11条回答
  •  孤街浪徒
    2020-11-22 00:05

    The classic way would be to add commas to the left and right:

    select * from shirts where CONCAT(',', colors, ',') like '%,1,%'
    

    But find_in_set also works:

    select * from shirts where find_in_set('1',colors) <> 0
    

提交回复
热议问题