SELECT
idName,SUM(Money),SUM(Revenue)
FROM
(
SELECT agentID AS idName,SUM(totalMoney) AS Money,0 AS Revenue FROM lm_agent_finance_webstat GROUP BY agentID
UNION ALL
SELECT agentID AS idName,0 AS Money,SUM(totalRevenue) AS Revenue FROM lm_agent_financestat GROUP BY agentID
) a
GROUP BY
idName
idName,SUM(Money),SUM(Revenue)
FROM
(
SELECT agentID AS idName,SUM(totalMoney) AS Money,0 AS Revenue FROM lm_agent_finance_webstat GROUP BY agentID
UNION ALL
SELECT agentID AS idName,0 AS Money,SUM(totalRevenue) AS Revenue FROM lm_agent_financestat GROUP BY agentID
) a
GROUP BY
idName