Sql nested select

database , sql , select Haifa, Israel
  • 10 years ago

    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

Post a reply

No one has replied yet! Why not be the first?

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“C++: an octopus made by nailing extra legs onto a dog.” - Steve Taylor