If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > subqueries with multiple tables & Sum

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-10-04, 09:58
sylviasue sylviasue is offline
Registered User
 
Join Date: Mar 2004
Location: Kuwait
Posts: 4
subqueries with multiple tables & Sum

Hi all,


i have the following 3 tables;

t_account
AccountID, Name, Address

t_corp_bond
CorpBondID, Principal

t_corp_bond_trans
CorpBondTransID, CorpBondID, AccountID, AllocatedPrincipal

The CorpID in t_corp_bond_trans is a foreign key from t_corp_bond table, and the AccountID is a foreign key from t_account table.

I am trying to build a query where i select only those rows in t_corp_trans rows where the Sum of AllocatedPrincipal in t_corp_trans is equal to the principal amount in t_corp where the CorpBondID in t_corp_bond table is equal to CorpBondID in the t_corp_bond_trans table.

i tried doing something like this with no luck;

select t_corp_bond_trans.* from t_corp_bond_trans, t_corp_bond
where t_corp_bond.CorpBondID= t_corp_bond_trans.CorpBondID
and t_corp_bond.Principal = (select SUM(t_corp_bond_trans.AllocatedPrincipal) where
t_corp_bond.CorpBondID = t_corp_bond_trans.CorpBondID
from t_corp_bond_trans)

Thanks in Advance for your help
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On