I have this table:
Table ___Products
|--------|----------|----------------|
| PRO_Id | PRO_Name | PRO_LinkedProd |
|--------|----------|----------------|
| 1 | Banana | 2,3,4 |
| 2 | Apple | 1,3 |
| 3 | Pear | 3 |
| 4 | Cherry | 1,2,3 |
|--------|----------|----------------|
I'm looking to loop in PRO_LinkedProd
for one product (Ex: Banana).
Desired output for Banana
should be:
|--------|----------|
| PRO_Id | PRO_Name |
|--------|----------|
| 2 | Apple |
| 3 | Pear |
| 4 | Cherry |
|--------|----------|
This is what I have tried so far:
SELECT *, IFNULL(GROUP_CONCAT(PRO_LinkedProd), ",") as list_prods
FROM ___Products p
INNER JOIN ___Products p ON p.PRO_LinkedProd like concat("%", p.PRO_Id, "%")
GROUP BY PRO_Id
ORDER BY PRO_Id ASC