Results 1 to 6 of 6
  1. #1
    PicoTTS is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2016
    Posts
    29

    Join 4 Tables

    Hi,

    I am having trouble joining 4 tables. I have 3 tables that are databases for different types of products and the fourth table houses all of the order details (customer name, address, etc). All 4 tables are linked by the Order ID

    My tables are generally formatted as follows.



    Table 1
    OrderID, Description

    Table 2
    OrderID, Description

    Table 3
    OrderID, Description

    Table4
    OrderID, Customer, Address

    My goal is to have a Union that lists all lines from table 1-3, and for each line, append that line with the corresponding Order info from table 4 based on the matching OrderID. I understand that I need to union all for first 3 tables but I am not sure how to join the fourth in the manner that I want. My guess is that I need to do an inner join but I have not been able to figure it out yet.

    Thanks

  2. #2
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,529
    Well, one would question why the 3 tables, but you'd join table 4 against each of the others separately. In other words, each of the 3 SQL statements in your UNION query would have a join.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    PicoTTS is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2016
    Posts
    29
    I had to keep 3 separate for each product type because they all have very different fields that define the characteristics of the product. In reality, the Description field I mentioned earlier is a concatenate of all the various characteristics.

    I currently came up with something like this: But it is not showing any of the info from table 4. It is only showing the OrderID and the Description Column.

    Select [Table1].OrderID, [Table1].DESCRIPTION from [Table1]
    Inner Join [Table4] On [Table1].OrderID=[Table4].[OrderID_Number]
    UNION ALL
    Select [Table2].OrderID, [Table2].DESCRIPTION from [Table2]
    Inner Join [Table4] On [Table2].OrderID=[Table4].[OrderID_Number]
    UNION ALL
    Select [Table3].OrderID, [Table3].DESCRIPTION from [Table3]
    Inner Join [Table4] On [Table3].OrderID=[Table4].[OrderID_Number]

  4. #4
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,529
    You'd have to add the field from table 4 to each of the SELECT clauses:

    Select [Table1].OrderID, [Table1].DESCRIPTION, Table4.Whatever from [Table1]
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    PicoTTS is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2016
    Posts
    29
    Perfect! This was exactly what I needed

  6. #6
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,529
    Happy to help!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. How to join tables
    By dollygg in forum Queries
    Replies: 1
    Last Post: 09-15-2015, 11:04 AM
  2. Replies: 8
    Last Post: 06-04-2014, 10:01 AM
  3. Replies: 6
    Last Post: 11-19-2013, 01:38 AM
  4. Join multiple tables to one
    By b6677862 in forum Queries
    Replies: 1
    Last Post: 02-08-2012, 06:59 AM
  5. Join 4 Tables in 1 Query
    By sandlucky in forum Queries
    Replies: 5
    Last Post: 06-12-2011, 06:28 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums