I have 3 tables: people, loans, and deposits
people: id, name, address etc
loans and deposits tables are identical:
id, sum,date etc
each person may have any number of loans or deposits, I want to know how much sum total money this person has in his account now.
for the loans:
select people.id,sum(loans.sum)
from people INNER JOIN loans ON people.id=loans.id
group by people.id
i did the same for the deposits table
select people.id,sum(deposits.sum)
from people INNER JOIN deposits ON people.id=deposits.id
group by people.id
How can I combine these two to get ONE number for each id?
I know there is something called a nested select, but I can't figure out how to add it in this case
!--removed tag-->
No one has replied yet! Why not be the first?
Sign in or Join us (it's free).