SELECT mysql column with comma separated values

后端 未结 4 942
一生所求
一生所求 2021-01-19 06:40

Consider I have a table like this.

+-------------+---------------+----------------+---------------+
+     id      +    column 1   +    column 2    +    column 3           


        
相关标签:
4条回答
  • 2021-01-19 06:47

    Try this

    SELECT  *
    FROM    table
    WHERE   FIND_IN_SET('$variable', column 3)
    
    0 讨论(0)
  • 2021-01-19 06:59

    mysql function find_in_set can search only for one string in a set of strings. the first argument is a string, so there is no way to make it parse your comma separated string into strings (you can't use commas in SET elements at all!). the second argument is a SET, which in turn is represented by a comma separated string hence your wish to find_in_set('a,b,c', 'a,b,c,d') which works fine, but it surely can't find a string 'a,b,c' in any SET by definition - it contains commas.

    SELECT * FROM tableName WHERE column 1 = 'values' and FIND_IN_SET('a',column3 )

    0 讨论(0)
  • 2021-01-19 07:06

    use FIND_IN_SET() -- a builtin function for mysql to search a string

    SELECT  *
    FROM    tableName
    WHERE column 1 = 'values' and  FIND_IN_SET('a',column 3 )>0
    
    • sample

    • REFER

    0 讨论(0)
  • 2021-01-19 07:09

    use this query select * from table where column 1 = 'values' AND column 3 like '%$value%'

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