Hi, I´ve tested LEFT OUTER in this way (to verify
that the correct “sums” are displayed):
select invoices.inumber,invoices.amount,sum(payments.amou nt),
sum(creditnotes.amount)
from invoices
left outer join payments on invoices.inumber=payments.inumber
left outer join creditnotes on invoices.inumber=creditnotes.inumber
where invoices.status='not paid'
group by invoices.inumber;
But there's a weird situation, an example results displayed are:
inumber sum(payments.amount) sum(creditnotes.amount)
1 20 6
2 30 12
...
but the real results must be:
inumber sum(payments.amount) sum(creditnotes.amount)
1 10 3
2 10 4
...
In invoice 1 there's only one payment of $10 and two credit notes
that sum $3, i think mysql is showing results x 2 because there are two records of credit notes.
The same situation happens in invoice 2: there are three payments
that sum $10 and one credit note that sum $4, and because there
are three records of payments the results displayed are x 3.
How can I avoid this situation? I think I´m really close to the end,
and I will be rocking and rolling!
Thanks in advance
Roland