Find value in comma delimited string mysql

前端 未结 3 1179
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-17 08:07

I have a table in my DB that looks like so:

member_id    name    mgroup_others    member_group_id
    1        Name1      2,3,10              1
    2                 


        
相关标签:
3条回答
  • 2021-01-17 08:22
    SELECT * FROM table WHERE FIND_IN_SET(10,mgoup_others)>0
    

    This is a temp solution,in a production db this will be slower than a turbo snail.

    0 讨论(0)
  • 2021-01-17 08:36

    Use LIKE

    SELECT * 
    FROM yourtable 
    WHERE mgroup_others LIKE '%10%'
    
    0 讨论(0)
  • 2021-01-17 08:45

    Since mgroup_others is a varchar column what if you simply use LIKE operator other than FIND_IN_SET() like

    select * from table1
    where mgroup_others like '%10'
    

    You can as well use FIND_IN_SET() like below

    select * from table1
    where find_in_set(10,mgroup_others)
    

    See a demo fiddle here http://sqlfiddle.com/#!2/034711/2

    0 讨论(0)
提交回复
热议问题