Improve company productivity with a Business Account.Sign Up


Ambiguous Outer Joins

Posted on 2002-03-18
Medium Priority
Last Modified: 2008-03-17
I do a report periodically that uses 3 semesters of course failure data.  The data for each semester is brought into Access as a separate table: e.g., Jan01, Jun01, Jan02.  The report will use several fields from the current table—in this case, Jan02—and one field from each of the earlier tables, Jan01 and Jun01.  I want to use a make table query to bring the selected fields from each table into a single table.  

In each table, the primary key is a composite of the school’s 4-digit unit number and 2-digit grade (called UntGrd); so, e.g., 101009 signifies 9th grade in unit 1010.  

I have no problem designating UntGrd as the primary key in each table, which implies that the values for UntGrd are unique in each table.  I have no problem relating the tables and enforcing referential integrity.  The most recent table (Jan02) is the primary table.  Therefore, referential integrity implies that all records in Jan01 and Jun01 are in Jan02.  There are no “orphans” in Jan01 and Jun01 although “childless parents” are permitted in Jan02.  The joins from Jan02 to Jan01 and Jun01 are left outer joins (all records in Jan02 and only the matching records in Jan01 and Jun01).

My problem is that when I run the make table query, I get the message “The SQL statement could not be executed because it contains ambiguous outer joins.  To force one of the joins to be performed first, create a separate query that performs the first join and then include that query in you SQL statement.”  I would expect the joins to be performed in the order that tables are called into the query; so, I obviously don’t understand the problem.  

Doing a work-around is easy enough.  I can run a make table query to join any two tables, say Jan01 and Jun01, to produce Temp01.  Then, I can run another make table query to join Temp01 and Jan02.  Fine, but I still would like to understand that error message.  100 points to anyone who can explain it.
Question by:doctortony
  • 5
  • 3
LVL 16

Expert Comment

ID: 6878303
Could you post the SQL (In the query Designer window,
 right-click the window and choose SQL).
LVL 16

Expert Comment

ID: 6878827

Assuming you want to retrieve the primary key, and the
field F2 that is in all your tables, into a new table
called NewTableName, you should have the following SQL
    Jun01.F2 AS F22,
    Jan01.F2 AS F23
   (Jan02 LEFT JOIN Jun01 ON Jan02.UntGrd = Jun01.UntGrd)
   LEFT JOIN Jan01 ON Jan02.UntGrd =Jan01.UntGrd
F22 new name in new table for field Jun02.F2
F23 new name in new table for field Jan01.F2
You should see something similar in your query SQL.
Depending on your field/table names, you'll have brackets
or apostrophes surrounding the field/table names.
Note that you can edit the SQL statement (if you think
Access did not translate correctly) then, when going
back to Design window, Access will update the query from
the SQL you just edited (before editing, copy/paste the
query with another name,... in case ...)

Hope this help,

Author Comment

ID: 6880618
If I right click in the query designer window and choose SQL View, it does not show me the SQL.  Instead, it tries to execute the query, and it returns the error message about ambiguous joins.
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

LVL 16

Expert Comment

ID: 6881238
Can you tell me the fields you want from these tables.
I'll create the SQl string then send it back to you, then:
-Create a new blank query in Access
-In SQL View, paste the SQL string
-Go back to query designer
--> this should translate the SQL into the usual diagramm

I'll also try to save the Query and send it to you, so
that you can import it. If the table/field names are the
same, it should work.


Author Comment

ID: 6882763
If it would help, I could email you an abbreviated copy of the Access database (all fields but only a few records per table).  You can email me directly at  What I'm really interested in is not just solving the problem but understanding the logic.  Given that Access accepts my attempt to enforce referential integrity, I don't see why the query sees the joins as "ambiguous."  I think it has something to do with the fact that the relationships among tables are 1-to-1.  But that's as far as I get.
LVL 16

Accepted Solution

sebastienm earned 400 total points
ID: 6884338
I got your email & dB.

I noticed that, in the query, there are 3
links, not 2 as you said in your first post.
    Table3 (Jan02)  --->  Table1 (Jan01)
    Table3 (Jan02)  --->  Table2 (Jun01)
and Table1 (Jan01)  --->  Table2 (Jun01)
It's hard to see in the Diagram because the tables are
aligned so the links are supperposed.
--> THIS is the problem

- In the diagram, Move your tables around to be able to see
  all 3 links
- Delete the link from Table1(Jan01) and Table2(Jun01)
that's it.

The engine doesn't like when the links form a loop
(closed-path) because it doesn't know which path to take
to return the data (Table2 data could be accessed trough
table 1 or table2). Some databases have optimizers for
these situations. But it should be avoided.
Sometimes you really need the table twice, eg:

Shipment Table (S)
-origin zip
-dest customer

Customer Table (C)

Location Table (L)

you want shipment number, origin city, destination city
S.o_zip ---
S.dest_cust --- ----
3 links but it makes a closed-path (loop)

So, what you should do, is to define the L table twice
(in Access, it is like putting the table L twice in the
diagram, the name of the second one will change to L_2)
S.o_zip ---
S.dest_cust --- ----

Hope this will fix the problem,

Author Comment

ID: 6889423
Thanks a million!  What puzzles me is that, if you check the relationships window in the DB I sent you, you'll notice that there are only two relationships: Table3-->Table1 and Table3-->Table2.  When I reconstructed the query (just now), I noticed that when I selected the three tables, indeed, Table1 was linked to Table2!  I always thought that once the relationships were defined (in the relationships window), they were set.  Any query acted on the relationships as they were set.  I didn't know that the act of constructing a query could somehow insert a new relationship independent of what was specified in the relationships module.  And, you're right, I did not see the link between Tables 1 and 2.  Because I thought the relationships were set, I could have sat there till Hell freezes over, and I would not have seen the problem.  Thanks, again.
LVL 16

Expert Comment

ID: 6889488
Thank you Tony.

Access tend to link fields with identical names eventhough
 the relationaships are set.

In menu Tools>Option, tab Tables/Queries, there is an
option called AutoJoin. Unchecking it may cancel this
behavior (not sure)

From MS help:
"Access automatically creates joins if you add two tables
to a query and the tables each have a field with the same
or compatible data type and if one of the join fields is a
primary key"


Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

This article presents several of my favorite code snippets.
You can use the network upload option and the Office 365 Import service to bulk-import PST files to user mailboxes. Network upload means that you upload the PST files a temporary storage area in the Microsoft cloud.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
Enter Foreign and Special Characters Enter characters you can't find on a keyboard using its ASCII code ... and learn how to make a handy reference for yourself using Excel ~ Use these codes in any Windows application! ... whether it is a Micr…

579 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question