0

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.

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Awesome! Yeah I'm not really worried about speed with this, since there really aren't going to be many in there record wise, it saves me from having to do a new form for adding and a second table for xreference.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.