Search code examples
mysqlwhere-in

MySQL multiple IN clause does not work


I have a MySQL table column rubrics which contains string value '61,80,112,256'. So I try execute that query:

select * from table where 256 in (rubrics) and 61 in (rubrics)

And no result returns. Any suggestions?


Solution

  • Since your rubrics column is a comma separated list the IN operator will not work.

    MySQL does have a function that can find a value in a string list so you should be able to use FIND_IN_SET():

    select *
    from yourtable
    where find_in_set(61, rubrics)
      or find_in_set(256, rubrics)
    

    See SQL Fiddle with Demo