php - Match delimeter(|) separated values field in mysql select query -


in mysql table 1 of field has values (1|2|3) stored in it.

  id   skills  ----  --------    1   1|2|3|5    2     2|4|5    3    4|6|3    4    5|2|3|1 

i want search , list id's based on skills matched. if want list id's of skill contains 3, have list ids 1,3,4. if want list id's of skill contains 1,5 (either 1 nor 5 or both)(like mulitple values 1,4,3) want list 1,2,4(i want list 2 also). appreciated.

thanks in advance.

use find_in_set

select id your_table find_in_set('3', replace(skills, '|',',') > 0  select id your_table find_in_set('3', replace(skills, '|',',')) > 0 or find_in_set('5', replace(skills, '|',',')) > 0 

but should change db structure. store single values in column avoid such problems!


Comments