select client, invoicedocument, invoiceamount,
ifnull((select sum(payamount) from table2
where table2.client = table1.client and table2.invoicedocument = table1.invoicedocument),0) as total_payamount
from table1
ok this should work:
This assumes you want invoice document and the amounts EVEN if there are no payments.
B4X:
SELECT Invoices.Client, InvoiceDocument, InvoiceAmount
SUM(payamount) as TotalPaid
FROM Invoices
LEFT JOIN Payments ON Payments.Client = Invoices.Client
GROUP BY Invoices.Client, InvoiceDocument, InvoiceAmount
Regards,
Albert D. Kallal
Edmonton, Alberta Canada