Join two tables with specific data

  • 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.

  • 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.



    Alvin Ramard
    Memphis PASS Chapter[/url]

    All my SSC forum answers come with a money back guarantee. If you didn't like the answer then I'll gladly refund what you paid for it.

    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]

  • 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

  • kennyhuang0108 (7/15/2015)


    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

    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.



    Alvin Ramard
    Memphis PASS Chapter[/url]

    All my SSC forum answers come with a money back guarantee. If you didn't like the answer then I'll gladly refund what you paid for it.

    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