I just ran into a problem.
I know these integers, $integers
: 3,5,15,20.
I only want to select the rows from this following table where all comma separated INT's from the field NUMBERS are found.
TABLE: number_table
Uid Numbers
------------------------
1 3,5,15 OK, since all of NUMBERS are in $integers
2 5,15,20 OK, since all of NUMBERS are in $integers
3 3,4,5,15 NOT OK, since 4 is not found in $integers
4 2,15,20,25 NOT OK, since 2 and 25 is not found in $integers
Is it possible to do a "for-each" on a comma separated string or another way to do this SELECT?
UPDATE: It sounds like this is not possible. I will leave it here for little while. Just a hint. When searching for something in a comma separated string then MySQL provides the WHEERE something IN (comma separated string). What I What I look for is someway to traverse a comma separated string using MySQL but that might not be possible.
Something like this would do it (pseudocode):
SELECT * FROM number_table WHERE each_commaseparated_substring(Numbers , 'IN (3,5,15,20)')