我想知道如何获得显示所有订单,与每个订单关联的所有发票以及与每个发票关联的所有付款的结果。我收到了订单及其相关发票,但只收到第一笔付款,而不是与一个发票相关的每笔付款。有什么建议吗?
SELECT orders.n_o, invoices.n_in, payments.n_pay
FROM orders
LEFT JOIN invoices ON order.n_o = invoices.n_o_fk
LEFT JOIN payments ON invoices.n_in = payments.n_pay_fk
GROUP BY invoices.n_in;
答案 0 :(得分:1)
大概您不希望GROUP BY
:
SELECT o.n_o, i.n_in, p.n_pay
FROM orders o LEFT JOIN
invoices i
ON o.n_o = i.n_o_fk LEFT JOIN
payments p
ON i.n_in = p.n_pay_fk ;