Results 1 to 3 of 3
  1. #1
    richjhart is offline Novice
    Windows XP Access 2003
    Join Date
    Sep 2010
    Posts
    2

    Multiple joins, avoiding cross joined result

    I would like to join three tables, using a common join column in one of the tables without it looking like cross join.

    I am using Access 2003

    So if I have three tables:
    Code:
    CommonTable:
    ID Col1
    -- ----
    1  Item1
    2  Item2
    
    Table1
    ID1 ForeignKey1 Col2
    --- ----------- ----
    1   1           SecondItem1
    2   1           SecondItem2
    
    Table2
    ID2 ForeignKey2 Col3
    --- ----------- ----
    1   1           ThirdItem1
    2   1           ThirdItem2
    So the normal join would be:
    (CommonTable INNER JOIN Table1 ON CommonTable.ID=Table1.ForeignKey) INNER JOIN Table2 ON CommonTable.ID=Table2.ForeignKey

    Which results in:


    Code:
    ID Col1  ID1 ForeignKey1 Col2        ID2 ForeignKey2 Col3
    -- ----- --- ----------- ----------- --- ----------- ----------
    1  Item1 1   1           SecondItem1 1   1           ThirdItem1
    1  Item1 2   1           SecondItem2 1   1           ThirdItem1
    1  Item1 1   1           SecondItem1 2   1           ThirdItem2
    1  Item1 2   1           SecondItem2 2   1           ThirdItem2
    But what I want is to separate the joining of Table1 and Table2 to CommonTable to end up with:
    Code:
    ID Col1  ID1 ForeignKey1 Col2        ID2 ForeignKey2 Col3
    -- ----- --- ----------- ----------- --- ----------- ----------
    1  Item1 1   1           SecondItem1 NULL
    1  Item1 2   1           SecondItem2 NULL
    1  Item1 NULL                        1   1           ThirdItem1
    1  Item1 NULL                        2   1           ThirdItem2
    At first I thought outer joins would do the trick, but gradually realised that didn't help in this case.
    Happy to use intermediate queries or whatever, but I just can't figure this one out

  2. #2
    Guigui is offline Novice
    Windows Vista Access 2007
    Join Date
    Sep 2010
    Posts
    11
    To me a union query of 2 queries (one with Table1 and one with Table2) would do.

  3. #3
    richjhart is offline Novice
    Windows XP Access 2003
    Join Date
    Sep 2010
    Posts
    2
    Cheers. Yeah a Union did the trick. I'd forgot about them.

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

Similar Threads

  1. Multiple outer joins - error message
    By Lipi in forum Queries
    Replies: 1
    Last Post: 09-16-2010, 02:44 PM
  2. Avoiding duplicates in query
    By theracer06 in forum Queries
    Replies: 1
    Last Post: 08-24-2010, 12:49 PM
  3. Re: Adding a new record to a joined table
    By Mcdodre in forum Access
    Replies: 4
    Last Post: 06-30-2010, 12:07 PM
  4. Multiple inputs one result
    By ee12csvt in forum Queries
    Replies: 0
    Last Post: 09-11-2009, 03:19 AM
  5. Multiple cross-references from one record
    By bpkcjgorr in forum Database Design
    Replies: 0
    Last Post: 01-03-2008, 02:33 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