I have an Access 2007 database where I have two tables, exp_cash and exp_cheque. Both are linked to exp_cat, where exp_cat contains categories list, and exp_cash and exp_cheque contain id, cat_id, exp_date, exp_amount, and exp_note.
When I tried to combine them nothing appears in the result unless I remove the cat_name from my query. I used a simple query:
SELECT DISTINCT
exp_cat.cat_name,
exp_cash.exp_amount,
exp_cheque.exp_amount
FROM (exp_cat INNER JOIN exp_cash
ON exp_cat.ID = exp_cash.exp_cat_id)
INNER JOIN exp_cheque
ON exp_cat.ID = exp_cheque.exp_cat_id;
Table exp_cat contains
exp_cat_name
exp_cat_id
exp_cat_id ----- exp_cat_name
1 ----- Salary
2 ----- Electricity
3 ----- Water Bill
4 ----- Loan
Table exp_cash contains
exp_cash_id
exp_date
exp_cat_id
exp_cash_amount
exp_invoice_no
exp_cash_id ----- exp_date ---- exp_cat_id ---- exp_cash_amount ---- exp_invoice_no
1 ----- 15/05/2010 -- 2 ---- 200 ---- 25AB5245
2 ----- 17/05/2010 -- 1 ---- 50 ---- 58624AA
Table exp_cheue contains
exp_cheque_id
exp_date
exp_cat_id
exp_cheque_amount
exp_invoice_no
exp_cheque_id ----- exp_date ---- exp_cat_id -- exp_cheque_amount -- exp_invoice_no
1 ----- 15/05/2010 -- 3 -- 120 -- 25AB5245
2 ----- 17/05/2010 -- 4 -- 500 -- 58624AA
I think what you want is left joins instead of inner joins:
Otherwise you must have the same exp_cat_id in both the exp_cash and exp_cheque tables.
The Inner joins only show what exists in both tables. The left join shows everything in the left table, and anything that happens to match in the right hand table (or null values if nothing matches).
Here’s what I get when I run that query with your data: