Reputation: 2349
I'm looking to do a simple comparison test in MySQL, I have a field that stores ID's like so:
1;2;23;12
Or if only one option was selected when creating that entry it would only be one:
2
At any rate I am looking to filter my select query to find entries in the DB that have for instance the ID 2 in them. So I need some sort of comparison to compare that id 2 against that column with those values and a possible single value.
Upvotes: 0
Views: 237
Reputation: 51655
You are looking for find_in_set function:
Select
*
from
your_table
where
FIND_IN_SET('2',REPLACE( '1;2;23;12', ';' , ',' ) ) > 0
I would recommend to you to normalize database (see: http://en.wikipedia.org/wiki/First_normal_form) Also, notice to you that this kind of queries don't has high performance.
Upvotes: 3