Search code examples
mysqlcsvselecttags

how to select based on comma separated values in column


In my table, one of the column has comma separated values. I would like to select the entry based on one or two values if found in that column like

select * from table where tags contains ('ec2' or 'associate')

or contains multiple values

select * from table where tags contains 's3' and 'rds'

What is the right query?

enter image description here


Solution

  • You can use the in-built find_in_set function.

    find_in_set('s3',tags) > 0 and find_in_set('rds',tags) > 0