D
Dave
I have the following query that uses a LEFT JOIN:
SELECT Investment.Investment,
Sum(IIf(IsNull([qr_Amount.Amount]),0,qr_Amount.Amount))
FROM Investment LEFT JOIN qr_Amount ON Investment.InvestID =
qr_Amount.InvestID
GROUP BY Investment.Investment
With this query I get back all of my investment categories reqardless of
whether a particular category has an amount associated with it in the
right-side table (qr_Amount, which is actually a query) as in the example
below:
Stocks 10
Mutual Funds 20
Insurance 0
Bonds 0
MMF 10
However, if I include a WHERE clause that operates on a field in the
right-side table, I do not get a record returned for each row in the
left-side table.
For example, this query....
SELECT Investment.Investment,
Sum(IIf(IsNull([qr_Amount.Amount]),0,qr_Amount.Amount))
FROM Investment LEFT JOIN qr_Amount ON Investment.InvestID =
qr_Amount.InvestID
WHERE qr_Amount.CheckDate BETWEEN #6/12/04# and #6/12/04#
GROUP BY Investment.Investment
....returns only this:
Stocks 10
Mutual Funds 20
MMF 10
Why is this?
I thought the function of a LEFT JOIN was to return all records in the
left-side table regardless of whether there was a match in the right-side
table? The WHERE clause operates only on the right-side table so why do I
lose my left-side table records without matches?
SELECT Investment.Investment,
Sum(IIf(IsNull([qr_Amount.Amount]),0,qr_Amount.Amount))
FROM Investment LEFT JOIN qr_Amount ON Investment.InvestID =
qr_Amount.InvestID
GROUP BY Investment.Investment
With this query I get back all of my investment categories reqardless of
whether a particular category has an amount associated with it in the
right-side table (qr_Amount, which is actually a query) as in the example
below:
Stocks 10
Mutual Funds 20
Insurance 0
Bonds 0
MMF 10
However, if I include a WHERE clause that operates on a field in the
right-side table, I do not get a record returned for each row in the
left-side table.
For example, this query....
SELECT Investment.Investment,
Sum(IIf(IsNull([qr_Amount.Amount]),0,qr_Amount.Amount))
FROM Investment LEFT JOIN qr_Amount ON Investment.InvestID =
qr_Amount.InvestID
WHERE qr_Amount.CheckDate BETWEEN #6/12/04# and #6/12/04#
GROUP BY Investment.Investment
....returns only this:
Stocks 10
Mutual Funds 20
MMF 10
Why is this?
I thought the function of a LEFT JOIN was to return all records in the
left-side table regardless of whether there was a match in the right-side
table? The WHERE clause operates only on the right-side table so why do I
lose my left-side table records without matches?