Problem: I have a piece of code that joins two tables on whether the amounts for the respective references from both add to zero. The issue is that I don't know how to include more columns in the resulting query.
SELECT *
FROM (SELECT PayRef, SUM(MerchAmount) AS FAmount
FROM qryPaymentReferenceConversion
GROUP BY PayRef) AS qryPaymentReferenceConversion
INNER JOIN (SELECT Reference, SUM(TransAmount) AS BAmount
FROM tblBankStatementRegisterMaster GROUP BY Reference) AS tblBankStatementRegisterMaster
ON tblBankStatementRegisterMaster.Reference =qryPaymentReferenceConversion.PayRef
WHERE qryPaymentReferenceConversion.FAmount + tblBankStatementRegisterMaster.BAmount = 0;
In addition, when I try this alternative, I get a syntax error. Problem: Whenever I compile the code below, I receive a syntax error in the JOIN operation. Is this because I am selecting all fields rather than specifying the Reference field from the bank table? If so, how do I select all tables while maintaining the relationship?
SELECT tblBankStatementRegisterMaster.*, TransAmt
FROM tblBankStatementRegisterMaster AS BAmount
INNER JOIN (SELECT PayRef, Sum(MerchAmt) AS FAmount
FROM qryPaymentReferenceConversion GROUP BY PayRef)
ON tblBankStatementRegisterMaster.Reference = qryPaymentReferenceConversion.PayRef
WHERE qryPaymentReferenceConversion.FAmount + tblBankStatementRegisterMaster.BAmount = 0;