Question : Ambiguous Outer Joins

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.

Answer : Ambiguous Outer Joins

Doctortony,
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

So:
- 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)
--------------
-number
-weight
-origin zip
-dest customer

Customer Table (C)
-------------
-name
-zip

Location Table (L)
---------------
-zip
-city
-state

you want shipment number, origin city, destination city
S.o_zip --- L.zip
S.dest_cust --- C.name
C.zip ---- L.zip
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)
Then:
S.o_zip --- L.zip
S.dest_cust --- C.name
C.zip ---- L_2.zip

Hope this will fix the problem,
Sébastien
Random Solutions  
 
programming4us programming4us