Nesting JOIN syntax

Colin@Toyota

What's an Access?
Local time
Today, 11:43
Joined
May 2, 2006
Messages
203
I am just wondering the proper procedure for nesting JOIN statements... I have a statement that is set up like this:

Code:
FROM (((table1
     LEFT JOIN (table2
          LEFT JOIN table3 ON table2.fieldA = table3.fieldA)
     ON table1.fieldB = table2.fieldB
     LEFT JOIN table4 ON table2.fieldC = table4.fieldC)
     LEFT JOIN table5 ON table1.fieldD = table5.fieldD)

I need to add another join, but it is three tables away...

Something along the lines of... (I would add this to the above SQL)

Code:
     INNER JOIN (table2 
          INNER JOIN (table3 
               INNER JOIN table6 ON table3.fieldX = table6.fieldX)
          ON table2.fieldA = table3.fieldA)
     ON table1.fieldB = table2.fieldB

I'm sure this is really quite vague, but if anyone can help I'd appreciate it! Also, bear in mind I am working with existing queries from the last person who took care of this db... and everything is so inter-connected, I can't really go too far towards changing as much as I'd like... I simply don't have the time.

Cheers,

Colin

EDIT: I tried running this, and it didn't like the syntax in my FROM clause, and highlighted the ON between table6 and table3
 
I think I figured it out...

Code:
FROM ((([19a) unique_lineup_shared_vehicle] 
     LEFT JOIN (DWP_D_PART LEFT JOIN DWP_F_PART_INVOICE ON 
          DWP_D_PART.PART_SID = DWP_F_PART_INVOICE.PART_SID) ON 
               [19a) unique_lineup_shared_vehicle].PartNumber = DWP_D_PART.PART_NUMBER) 
     LEFT JOIN DWP_D_PART_ANALYST ON 
          DWP_D_PART.ORDER_ANALYST_CODE = DWP_D_PART_ANALYST.ANALYST_CODE) 
     LEFT JOIN Part ON 
          [19a) unique_lineup_shared_vehicle].PartNumber = Part.PartNumber) 
     INNER JOIN DWP_D_DEALER ON
          DWP_F_PART_INVOICE.DEALER_SID = DWP_D_DEALER.DEALER_SID
 
Nope, that's not it.

Access didn't like the relationships between the tables... I got the following error 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 seperate query that performs the first join and then include that query in your SQL statement."

So I'm thinking this is because I am trying to pull data from a series of tables where based on a many to many relationship... ?
 

Users who are viewing this thread

Back
Top Bottom