Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

joining multiple tables

Status
Not open for further replies.

rtantek

IS-IT--Management
Jan 29, 2003
6
US
i have 3 tables: accounts, bank1, bank2. i need to sum the field [mybalance] from both bank1 and bank2 where acctnum from bank1 and bank2 exist in accounts. all acctnum in bank1 are in accounts; all of acctnum in bank2 are in accounts; none of acctnum in bank1 are in bank2 and vice versa.

desired result:
accounts.acctnum, sum(bank1.mybalance + bank2.mybalance)

can this be done without the use of views.

Please help.
 
[tt]select accounts.acctnum
, sum(mybalance)
from accounts
inner
join (
select acctnum
, mybalance
from bank1
union all
select acctnum
, mybalance
from bank2
) as u
on accounts.acctnum = u.acctnum
group
by accounts.acctnum[/tt]

rudy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top