Table "skus":
plant_species_ids |
---|
1,2,3,2,3,1 |
Table "plant_species"
id | name |
---|---|
1 | Plant 1 |
2 | Plant 2 |
3 | Plant 3 |
The relevant part of my MySQL code:
...
GROUP_CONCAT(plant_species.name SEPARATOR ', ') as plant_species_names
...
LEFT JOIN plant_species
ON FIND_IN_SET(plant_species.id, skus.plant_species_ids) > 0
Output I get:
Plant 1,Plant 2,Plant 3
Result I need to get:
Plant 1,Plant 2,Plant 3, Plant 2,Plant 3,Plant 1
From what I can tell it's acting like I'm using DISTINCT when I'm not.
Any ideas how to do this?
Edit
Here is my final code for anyone else that has this same problem: ``
SELECT orders.id, orders.customer_id, orders.invoice_amount, orders.delivery_date, orders.delivery_time, GROUP_CONCAT(skus.name SEPARATOR ', ') as sku_name, orders.sku_ids as sku_ids, orders.sku_weights as sku_weights
FROM orders
JOIN json_table(concat('[',orders.sku_ids,']'), '$[*]' columns (id int path '$')) AS species_ids
LEFT JOIN skus on skus.id=species_ids.id
WHERE orders.id=10
GROUP BY orders.id;
``