I have three tables orders, ordered_dishes, ordered_dish_options.
orders
------
order_id | customer_name
1 | John smith
ordered_dishes
--------------
order_id | ordered_dish_id | dish_id | amount
1 | 1 | 3 | 1
1 | 2 | 3 | 2
1 | 3 | 6 | 1
ordered_dish_options
--------------------
order_id | ordered_dish_id | dish_option_id
1 | 1 | 2
1 | 2 | 4
1 | 3 | 3
note: in this example there are two dishes with dish_id=3 but the dish+dish_option combination is different.
I have the following query:
"SELECT orders.*,
GROUP_CONCAT(ordered_dishes.dish_id SEPARATOR ', ') dish_ids,
GROUP_CONCAT(ordered_dishes.amount SEPARATOR ', ') dish_amounts,
GROUP_CONCAT(ordered_dishes.ordered_dish_id SEPARATOR ', ') dish_odi,
GROUP_CONCAT(ordered_dish_options.ordered_dish_id SEPARATOR ', ') do_odi,
GROUP_CONCAT(ordered_dish_options.dish_option_id SEPARATOR ', ') dish_option_ids
FROM orders
LEFT JOIN ordered_dishes ON orders.order_id=ordered_dishes.order_id
LEFT JOIN ordered_dish_options ON orders.order_id=ordered_dish_options.order_id
WHERE orders.order_id=1"
this query gives my this:
order_id,
orderdata,
dish_ids='3,3,6,3,3,6,3,3,6',
dish_amounts='1,2,1,1,2,1,1,2,1',
dish_odi='1,2,3,1,2,3,1,2,3',
do_odi='1,1,1,1,1,1,1,1,1'
dish_option_id='2'
What I want is all order_data, dish_id + amounts + ordered_dish_id, dish_option_id + ordered_dish_id. I want the ordered_dish_ids from the last two tables to link the dish_option to the corresponding dish.