July 15, 2015 at 5:30 pm
Hi,
I have two queries from two different tables ex ABC and BCD. For table ABC, according to my query, I got 11 records ; for table BCD I only got 9 records.
Bottom line: I would like to see only 11 records from Table ABC including certain data from table BCD after I joined this two tables.
However, no matter what I did I always got 99 records when I joined.
please help!
thank you.
July 15, 2015 at 5:46 pm
Looks like you have a problem with your join statement.
There's no was we can help you without more information about the structure of your tables, the data the contain, and the query to wrote.
For best practices on asking questions, please read the following article: Forum Etiquette: How to post data/code on a forum to get the best help[/url]
July 15, 2015 at 5:51 pm
Thank you. here is my Query
select Orgn.cd, fund.cd,fund.nm, fund.bf_Acty_Cd
from
(
select cd,nm, bf_Acty_Cd
from bf_fund ---> 9 records
where bf_Acty_Cd ='402'
) fund
inner join
(
select cd,bf_Acty_Cd
from bf_orgn ---> 11 records
where cd like 'H%' and bf_Acty_Cd ='402'
) Orgn
on fund.bf_Acty_Cd =Orgn.bf_Acty_Cd --> they share the same column
July 15, 2015 at 6:04 pm
kennyhuang0108 (7/15/2015)
Thank you. here is my Queryselect Orgn.cd, fund.cd,fund.nm, fund.bf_Acty_Cd
from
(
select cd,nm, bf_Acty_Cd
from bf_fund ---> 9 records
where bf_Acty_Cd ='402'
) fund
inner join
(
select cd,bf_Acty_Cd
from bf_orgn ---> 11 records
where cd like 'H%' and bf_Acty_Cd ='402'
) Orgn
on fund.bf_Acty_Cd =Orgn.bf_Acty_Cd --> they share the same column
Since you are joining on only one column, bf_Acty_cd, every one of the 9 records from one query is getting joined to every one of the 11 records from the second query, so you get 9 * 11 = 99 records.
Normally joining adding a second column to the join is what's required to fix this.
That's about all I can say without seeing the data and what you're expecting as result.
For best practices on asking questions, please read the following article: Forum Etiquette: How to post data/code on a forum to get the best help[/url]
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply