I am working on a php project to retrieve data from mysql. I have a list of codes that is stored as a string separated by commas that is referenced in another table. Is there a way to get all the value from the string and return the text it referenced?
For example, item_purchased might contain one or more than one item_code. I want the query to return item names instead of item codes.
//item_purchased for transaction 123 --> ,111,222,333,
SELECT s.transaction_id, s.item_purchased, i.item_id
FROM stock s
INNER JOIN ref_item i
ON s.item_code = i.item_code
WHERE transaction_id = 123
Desired outcome: apple, carrot, milk (not ,111,222,333,)
Is there a way to do this preferably within mySQL query or maybe in PHP?