I have a transactions table, each transaction has an address field which references a row in an address table, each address in the address table has a coinID.
I want to get a sum of all transactions for EVERY coin for a specific user.
The problem I have is that if a user has 0 transactions or addresses that belong to a specific coin it is completely missing from the result. I need all coins in a coin table that have 0 transactions or addresses to return with a sum of 0.
SELECT coins.name, SUM(transactions.amount),coins.price_usd
FROM coins
LEFT JOIN addresses ON addresses.coin_id = coins.id
LEFT JOIN transactions ON transactions.address = addresses.address
LEFT JOIN users ON transactions.user_id = users.id
WHERE users.email = '[email protected]'
GROUP BY coins.name, coins.price_usd