I need help with a query that involves the joining of 3 tables. I have tables Customers, Registers and Transactions
Customers relates to Registers on the key customer_id.
Registers relates to Transactions on the key register_id.
I want to return a SUM of the columns 'retail' and 'cost' from Transactions by Customer.
I need a query something like
SELECT Customers.name, Customers.customer_id, Register.register_id, SUM(Transactions.retail) AS retail, SUM(Transactsions.cost) AS cost
FROM (Customers <JOIN TYPE> Registers ON Customer.customer_id = Registers.customer_id) <JOIN TYPE> Transactions ON Register.register_id = Transactions.register_id
WHERE Transactions.date=#<date>#
GROUP BY Customers.name, Customers.customer_id, Registers.register_id
If there are no transaction data for a register I still want 0's to show up in the result set, ie:
NAME ID REG ID RETAIL COST
A 0001 A0001-1 35.00 15.67
B 0002 B0001-1 0 0 <- no transactions for register for this customer
How do I create/modify my query to give this result? I guess this is based on the join type, I've tried doin a LEFT JOIN for the join type but do not get the results I am looking for. Thanks for any help.