Table 1 - sales
sales_id
Table 2 - order_order id | sales_id | id_pastel
Table 3 - Tracking item
id | id_item_pedido | id_accounting
Example: I make a sale with two items and their accompaniments:
A cake:
meat (item_edited)
Side dishes (item_accompaniment)
onion and parsley.
A cake:
chicken (item_edited)
Follow-up:
catupiry (item_accompaniment).
Separately I can even bring:
SELECT venda.id_venda,
GROUP_CONCAT(item_pedido.id_pastel) AS id_pastel
FROM venda
JOIN item_pedido ON item_pedido.id_venda = venda.id_venda GROUP BY item_pedido.id_venda
SELECTitem_pedido.id_venda,item_pedido.id_pastel,GROUP_CONCAT(item_acompanhamento.id_acompanhamento)ASid_acompanhamentoFROMitem_pedidoJOINitem_acompanhamentoONitem_pedido.id=item_acompanhamento.id_item_pedidoGROUPBYitem_pedido.id
But I would like to bring only one sale with the two items with their respective accompaniments.