Below is the actual invoice table

After grouping it based on invoiceID, the resultset is

And actual payment table is

and its payment resultset after grouping based on invoiceID is

Now i want to join these two resultsets [Payment and Invoice table] and find the balance amount subtracting Total from Amount based on InvoiceID and for non matching records the balance column should be zero. I tried this, but didn’t get the expected result.
Try something like this,