Results 1 to 11 of 11
  1. #1
    jamal numan is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jan 2011
    Location
    Ramallah, West Bank
    Posts
    113

    Question How to apply “Full Uuter Join” in Access in order to combine multiple tables based on an ID that is

    How to apply “Full Uuter Join” in Access in order to combine multiple tables based on an ID that is not available in all of them?

    I wanted to join the tables T1, T2, T3 while the expected result is T4.
    Which inquiry can perform this?


    The data is here:
    http://www.mediafire.com/file/erfipr...rJoin.mdb/file

    In SQL server, this can be accomplished with the code below:

    SELECT
    COALESCE(T1.F1, T2.S1, T3.H1) AS R1,
    T1.F2 AS R2,
    T2.S2 AS R3,
    T3.H2 AS R4
    FROM T1
    FULL OUTER JOIN T2 ON T2.S1 = T1.F1
    FULL OUTER JOIN T3 ON T3.H1 = T1.F1

    Thank you

    Jamal


    Click image for larger version. 

Name:	Clip_700.jpg 
Views:	13 
Size:	244.1 KB 
ID:	39006

    Click image for larger version. 

Name:	Clip_699.jpg 
Views:	14 
Size:	148.4 KB 
ID:	39007

    Click image for larger version. 

Name:	Clip_694.jpg 
Views:	13 
Size:	254.8 KB 
ID:	39008

  2. #2
    isladogs's Avatar
    isladogs is offline Access MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,204
    Access doesn't support full outer joins.
    Either use a UNION query or run the query in SQL Server and save as a view which you can then link to your Access db.
    Note that both of these will be read only.
    If you need your data to be editable then you will need to assign a primary key to the view or create a temp table for later synchronisation.

    An easier solution would be to merge the tables in SQL Server
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

  3. #3
    jamal numan is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jan 2011
    Location
    Ramallah, West Bank
    Posts
    113
    Quote Originally Posted by isladogs View Post
    Access doesn't support full outer joins.
    Either use a UNION query or run the query in SQL Server and save as a view which you can then link to your Access db.
    Note that both of these will be read only.
    If you need your data to be editable then you will need to assign a primary key to the view or create a temp table for later synchronisation.

    An easier solution would be to merge the tables in SQL Server
    Many thanks isladogs for the help.

    How can I use the union query in Access to end up with the expected result?

    Could you please help my with the code?

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    A UNION query alone won't accomplish this. Couple ways to do this. Try this approach.

    First query is the UNION:

    SELECT F1 AS R1, F2 AS D1, Null AS D2, Null AS D3 FROM T1
    UNION SELECT S1, Null, S2, Null FROM T2
    UNION SELECT H1, Null, Null, H2 FROM T3;

    Use that query in an aggregate query.

    SELECT R1, Max(D1) AS R2, Max(D2) AS R3, Max(D3) AS R4 FROM Query1 GROUP BY R1;

    Another approach:

    Again, first query is UNION:

    SELECT F1 AS R1 FROM T1
    UNION SELECT S1 FROM T2
    UNION SELECT H1 FROM T3;

    Now build another query that JOINS all 3 tables to the UNION query.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,941
    a slightly different approach, still using a union query

    qryR1 - get the distinct ID's
    Code:
    SELECT F1 AS R1 FROM T1
    UNION SELECT S1 FROM T2
    UNION SELECT H1 FROM T3
    Now you can left join to the three tables - note access uses bracketing in the FROM clause
    Code:
    SELECT R1, F2 AS R2, S2 AS R3, H2 AS R4
    FROM ((qryR1 R LEFT JOIN T1 ON R.R1=T1.F2) LEFT JOIN T2 ON R.R1=T2.S2)  LEFT JOIN T3 ON R.R1=T3.H2
    edit: just realised this is a fuller answer to June's second suggestion - sorry June!

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    Is okay, but you got the first line of SELECT a little mixed up - the field alias in wrong place.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,941
    getting too old for this! have corrected the code

  8. #8
    isladogs's Avatar
    isladogs is offline Access MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,204
    Hi Jamal
    Sorry about the delay in replying but June and Ajax have given the details of what my response was intended to mean.
    However, I would still consider doing it in SQL Server and then create a view to use in Access
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

  9. #9
    jamal numan is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jan 2011
    Location
    Ramallah, West Bank
    Posts
    113

    Question

    Quote Originally Posted by Ajax View Post
    a slightly different approach, still using a union query

    qryR1 - get the distinct ID's
    Code:
    SELECT F1 AS R1 FROM T1
    UNION SELECT S1 FROM T2
    UNION SELECT H1 FROM T3
    Now you can left join to the three tables - note access uses bracketing in the FROM clause
    Code:
    SELECT R1, F2 AS R2, S2 AS R3, H2 AS R4
    FROM ((qryR1 R LEFT JOIN T1 ON R.R1=T1.F2) LEFT JOIN T2 ON R.R1=T2.S2)  LEFT JOIN T3 ON R.R1=T3.H2
    edit: just realised this is a fuller answer to June's second suggestion - sorry June!
    Many thanks guys for the help.
    I tried ajax code but ended up with the following:

    Click image for larger version. 

Name:	Clip_710.jpg 
Views:	11 
Size:	222.1 KB 
ID:	39009

    Click image for larger version. 

Name:	Clip_711.jpg 
Views:	11 
Size:	197.0 KB 
ID:	39010

  10. #10
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,941
    my bad - too many similar names, joining to the wrong fields


    Code:
    SELECT R1, F2 AS R2, S2 AS R3, H2 AS R4
    FROM ((qryR1 R LEFT JOIN T1 ON R.R1=T1.F1) LEFT JOIN T2 ON R.R1=T2.S1)  LEFT JOIN T3 ON R.R1=T3.H1

  11. #11
    jamal numan is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jan 2011
    Location
    Ramallah, West Bank
    Posts
    113
    Quote Originally Posted by Ajax View Post
    my bad - too many similar names, joining to the wrong fields


    Code:
    SELECT R1, F2 AS R2, S2 AS R3, H2 AS R4
    FROM ((qryR1 R LEFT JOIN T1 ON R.R1=T1.F1) LEFT JOIN T2 ON R.R1=T2.S1)  LEFT JOIN T3 ON R.R1=T3.H1
    Many thanks for the prompt help Ajax. It works fine with me
    Best
    Jamal

    Click image for larger version. 

Name:	Clip_717.jpg 
Views:	9 
Size:	231.2 KB 
ID:	39022

    Click image for larger version. 

Name:	Clip_718.jpg 
Views:	9 
Size:	206.3 KB 
ID:	39023

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

Similar Threads

  1. Combine multiple Inner Join same table
    By kaylachris in forum Queries
    Replies: 11
    Last Post: 03-12-2019, 05:37 AM
  2. Access SQL - FULL OUTER JOIN
    By johnseito in forum Queries
    Replies: 3
    Last Post: 08-08-2017, 08:26 AM
  3. Replies: 5
    Last Post: 08-22-2014, 05:01 AM
  4. Replies: 2
    Last Post: 01-16-2014, 09:00 AM
  5. Combine Multiple Access Files into One and Append Tables
    By KLTurner in forum Import/Export Data
    Replies: 10
    Last Post: 01-02-2014, 11:38 AM

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