Ambiguous left joins in MS Access

后端 未结 2 1916
难免孤独
难免孤独 2021-01-20 06:10

I want to convert the following query from T-SQL

SELECT
    * 
FROM
    A                            LEFT JOIN
    B ON A.field1 = B.field1     LEFT JOIN
            


        
相关标签:
2条回答
  • 2021-01-20 06:40

    From Help LEFT JOIN, RIGHT JOIN Operations

    You can link multiple ON clauses. See the discussion of clause linking in the INNER JOIN topic to see how this is done.

    You can also link several ON clauses in a JOIN statement, using the following syntax:

    SELECT fields 
    FROM table1 
         INNER JOIN table2 ON table1.field1 compopr table2.field1 
                              AND ON table1.field2 compopr table2.field2)
                              OR ON table1.field3 compopr table2.field3)];
    

    But works this (it seems there is an error in help):

    SELECT * 
    FROM A 
         LEFT JOIN B ON A.field1 = B.field1
         LEFT JOIN C ON (C.field1 = A.field2 AND C.field2 = B.field2)
    
    0 讨论(0)
  • 2021-01-20 06:42

    You need a derived table to make this work in MS Access:

    SELECT * 
    FROM (
       SELECT A.Field1, A.Field2 As A2, B.Field2 
       FROM A 
       LEFT JOIN B ON A.field1 = B.field1) AS x 
    LEFT JOIN C ON  x.A2 = C.field1 AND  x.field2= C.field2 
    
    0 讨论(0)
提交回复
热议问题