I have to build a report from some data stored on a MySQL table and everything was going smoothly until I noticed that we are storing multiple values in one column. This is what I mean:
FIELDS: ID | CHOICES | AGE
VALUES: 1 | apple|orange|pear | 23
VALUES: 2 | peach|orange|pineapple|pear | 29
I need to search that table and find out how many users like pear, how many like orange, etc.
It would be a GROUP BY on that value but how do I break the contents of the CHOICE column into individual fields so I can search and group them like that? This code is executed from a PHP file, so I could also pre-process the data if needed, although I would prefer to do everything in the query if possible.
Thanks a lot in advance.
If you can’t change the database design I would recommend doing this in PHP.
Loop over the result:
Then you have an array indexed by fruit with an array of ids as a value
BUT change the database design if possible