4

我正在尝试解决其他人的 MS Access 查询并不断收到无效操作错误。帮助似乎不适用,因为我只是在运行查询。一切正常,INNER JOINS但是当我切换回LEFT JOIN错误时。


SELECT *
 FROM ((((orders 
 INNER JOIN orders_customers ON orders.CUST_ORDER_ID = orders_customers.ID) 
 LEFT JOIN quoted_theory ON orders.PART_ID = quoted_theory.PART_ID) 
 LEFT JOIN conversions ON orders.PART_ID = conversions.PART_ID) 
 LEFT JOIN dbo_WO_Header ON orders.CUST_ORDER_ID = dbo_WO_Header.PPC_Number) 
 INNER JOIN lines_qry ON orders.CUST_ORDER_ID = lines_qry.WORKORDER_BASE_ID

我可以得到一个级别LEFT JOIN,但每次我添加一秒LEFT JOIN时都会弹出错误。

4

2 回答 2

3

混合 INNER 和 LEFT 联接时,Access' db 引擎经常停止。如果该查询在没有最后一个内部连接的情况下工作......

SELECT *
FROM
    (((orders INNER JOIN orders_customers
    ON orders.CUST_ORDER_ID = orders_customers.ID)
    LEFT JOIN quoted_theory
    ON orders.PART_ID = quoted_theory.PART_ID)
    LEFT JOIN conversions
    ON orders.PART_ID = conversions.PART_ID)
    LEFT JOIN dbo_WO_Header
    ON orders.CUST_ORDER_ID = dbo_WO_Header.PPC_Number

...然后您可以尝试将该部分作为子查询和子查询的内部连接lines_qry。它可能会克服错误。

SELECT *
FROM
    (
        SELECT *
        FROM
            (((orders INNER JOIN orders_customers
            ON orders.CUST_ORDER_ID = orders_customers.ID)
            LEFT JOIN quoted_theory
            ON orders.PART_ID = quoted_theory.PART_ID)
            LEFT JOIN conversions
            ON orders.PART_ID = conversions.PART_ID)
            LEFT JOIN dbo_WO_Header
            ON orders.CUST_ORDER_ID = dbo_WO_Header.PPC_Number
    ) AS sub
    INNER JOIN lines_qry
    ON sub.CUST_ORDER_ID = lines_qry.WORKORDER_BASE_ID

如果任何其他表除了orders包含一个名为 的字段CUST_ORDER_ID,您将需要SELECT *在子查询中以外的其他内容以避免歧义。

于 2012-09-05T02:24:52.160 回答
0
SELECT *
FROM
    (
        SELECT *
        FROM
            (((orders INNER JOIN orders_customers
            ON orders.CUST_ORDER_ID = orders_customers.ID)
            LEFT JOIN quoted_theory
            ON orders.PART_ID = quoted_theory.PART_ID)
            LEFT JOIN conversions
            ON orders.PART_ID = conversions.PART_ID)
            LEFT JOIN dbo_WO_Header
            ON orders.CUST_ORDER_ID = dbo_WO_Header.PPC_Number
    ) AS sub
    INNER JOIN lines_qry
    ON sub.CUST_ORDER_ID = lines_qry.WORKORDER_BASE_ID
于 2014-09-24T15:44:00.823 回答