I have three MySQL queries I need to combine into a single query using joins. I'm having a lot of trouble figuring out how to do it though. Here are the three queries.
select
sum(A.a)
from A join B
on A.BID = B.id
where B.userID=userID
select
sum(C.c)
from D left join (C)
on (D.id=C.DID)
where D.userID = userID
select sum(E.e) from E where E.userID=userID
I need to somehow combine all of these queries into a single query joined with the user table to give me sum(A.a)+sum(C.C)+sum(E.e)
for each user.id. I tried a left join across all tables
user left join (A, B, C, D, E)
on ((A.BID = B.id and B.userID=user.id)
or (D.id=C.DID and D.userID = user.id)
or (E.userID=user.id))
It was pretty much a shot in the dark and it failed spectacularly. I have no idea how to combine these three queries, anyone give me a hint?
Edit to clarify: I need this query to be a join of the user table with the above queries, because I need to be able to select all user ids ordered by the sum_value. The three previous queries were run individually and parameterized with a single userID.
Futher edit: Tried every variation of union all joined to the user query I could think it, it doesn't work. It comes very close to working with some tweaking, but it still returns incorrect values. I'm not really sure why it is doing that.