SELECT
user.`id`,
user.`login`,
SUM(moneyuser.money)- SUM(payments.money) AS 'sum'
FROM
`user`
JOIN `moneyuser` ON (user.login = moneyuser.user)
JOIN `payments` ON (user.login = payments.user)
GROUP BY
user.id
SELECT
user.`id`,
user.`login`,
COALESCE(salary_table.`money_sum`, 0)-COALESCE(spending_table.`money_sum`, 0) AS 'sum'
FROM
`user`
LEFT JOIN (
SELECT
salary.user,
SUM(salary.`money`) AS 'money_sum'
FROM salary
GROUP BY salary.`user`
) salary_table ON salary_table.`user`= user.`id`
LEFT JOIN (
SELECT
spending.user,
SUM(spending.`money`) AS 'money_sum'
FROM spending
GROUP BY spending.`user`
) spending_table ON spending_table.`user`= user.`id`
GROUP BY user.`id`
select u.id, u.login
coalesce(income.sum, 0) - coalesce(payment.sum, 0) as balance
from users u
left join (
select user_id, sum(money) as sum from moneyuser group by user_id
) income ON u.id = income.user_id
left join (
select user_id, sum(money) as sum from payments group by user_id
) payment ON u.id = payment.user_id
where payment.user_id is null and income.user_id is null