I\'m here with this (I\'m sure it is) simple question I can\'t figure out how to solve.
I have this schema:
SELECT name, IFNULL(f.total, 0) AS total_fruit, IFNULL(c.total, 0) AS total_cookie
FROM person AS p
LEFT JOIN (SELECT person_idperson, SUM(cost) AS total
FROM fruit
GROUP BY person_idperson) AS f
ON p.idperson = f.person_idperson
LEFT JOIN (SELECT person_idperson, SUM(cost) AS total
FROM cookie
GROUP BY person_idperson) AS c
ON p.idperson = c.person_idperson
SELECT p.name AS PERSON_NAME,
IFNULL(SUM(f.cost),0) AS TOTAL_FRUIT,
IFNULL(SUM(c.cost),0) AS TOTAL_COOKIE
FROM person AS p
LEFT JOIN fruit as f
ON p.idperson = f.person_idperson
LEFT JOIN cookie as c
ON p.idperson = c.person_idperson
GROUP BY p.idperson