JOIN in Multiple Tables

  • Hello - I am using 4 tables; tblOne, tblTwo, tblThree, and tblFour. All of these tables have a common column called 'BK_ID'. Based on this column name, I'd like to pull the following data:

    SELECT BK_ID, Cburg, Hburg,Bmac,Soda

    From tblOne, I need Cburg, where BK_ID in tbleOne = BK_ID in tbleTne

    From tblTwo, I need Hburg, where BK_ID in tbleOne = BK_ID in tbleTwo

    From tblThree, I need Bmac, where BK_ID in tbleOne = BK_ID in tbleThree

    From tblFour, I need Soda, where BK_ID in tbleOne = BK_ID in tbleFour

    I appreciate your help. Thank you.

  • check out this quick tutorial on how to do joins. http://www.w3schools.com/sql/sql_join_inner.asp%5B/url%5D

    should be enough info to get you want you want.

    Bob
    -----------------------------------------------------------------------------
    How to post to get the best help[/url]

  • Something like below should work:

    select t1.Cburg,t2.Hburg,t3.Bmac,t4.Soda

    from table1 t1 inner join table2 t2 on t1.BK_ID=t2.BK_ID

    inner join table3 t3 on t2.BK_ID=t3.BK_ID

    inner join table4 on t3.BK_ID=t4.BK_ID

  • From tblOne, I need Cburg, where BK_ID in tbleOne = BK_ID in tbleTne

    From tblTwo, I need Hburg, where BK_ID in tbleOne = BK_ID in tbleTwo

    From tblThree, I need Bmac, where BK_ID in tbleOne = BK_ID in tbleThree

    From tblFour, I need Soda, where BK_ID in tbleOne = BK_ID in tbleFour

    query:

    SELECT tblOne.BK_ID, tblOne.Cburg, tblTwo.Hburg,tblThree.Bmac,tblFour.Soda

    from From tblOne

    inner join tblTwo on tblOne.BK_ID=tblTwo.BK_ID

    inner join tblThree on tblTwo.BK_ID=tblThree.BK_ID

    inner join tblFouron tblThree.BK_ID=tblFour.BK_ID

  • No! Without tables structure and some sample data you don't get the correct answer, anyway you should follow the rules to post the problem and it is describe in my signature!

    Have a nice day!

    😉

    ============================================================
    SELECT YOUR PROBLEM FROM SSC.com WHERE PROBLEM DESCRIPTION =
    http://www.sqlservercentral.com/articles/Best+Practices/61537/[/url]

  • Thanks for the people who are posting the solutions and it might be ok, but if you want the best solution for you problem ...see my signature!

    ============================================================
    SELECT YOUR PROBLEM FROM SSC.com WHERE PROBLEM DESCRIPTION =
    http://www.sqlservercentral.com/articles/Best+Practices/61537/[/url]

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply