3

我的数据库包括几个查找表(在 UI 表单上显示为下拉菜单)。

例如,

customer_data - 客户人口统计信息。

lookup_car - 存储汽车描述(Pinto、Vega、Reliant Robin、Mustang、Corvette)

junction_car_customer - 将客户与一辆或多辆汽车连接起来

客户 Jeremy Clarkson (cust_id: 1) 拥有三辆汽车。他的记录下拉菜单显示:

Pinto (car_id=100)
Reliant Robin (car_id=101)
Vega (car_id=102)

junction_car_customer 数据如下所示:

cust_id    car_id
1          100
1          101
1          102

我正在尝试返回显示客户名称和拥有的模型的行。

这是我的查询:

SELECT 
 cd.cust_id,
 cd.name_first,
 cd.name_last,
 jcc.car_id,
 lc.car_desc
FROM
 customer_data AS cd
 LEFT JOIN ju_cust_car AS jcc ON jcc.cust_id = cd.cust_id
 LEFT JOIN lookup_cars AS lc ON lc.car_id = jcc.car_id

ORDER BY 
 cd.name_last

我越来越:

查询表达式“jcc.cust_id = cd.cust_id LEFT JOIN lookup_cars AS lc ON lc.car_id = jcc.car_id”中的语法错误(缺少运算符)

是什么导致了这个错误?

4

2 回答 2

1

Access 对 LEFT/RIGHT JOIN 和括号有点挑剔。尝试这个

SELECT 
    cd.cust_id,
    cd.name_first,
    cd.name_last,
    jcc.car_id,
    lc.car_desc
FROM
    (
        customer_data AS cd
        LEFT JOIN 
        ju_cust_car AS jcc 
            ON jcc.cust_id = cd.cust_id
    )
    LEFT JOIN lookup_cars AS lc 
        ON lc.car_id = jcc.car_id
ORDER BY 
 cd.name_last
于 2013-11-04T13:54:41.703 回答
1

访问需要括号来表示多个连接。例如:

select * 
from ((Table1 as t1)
left join Table2 as t2 on t1.id = t2.id)
left join Table3 as t3 on t1.id = t3.id
于 2013-11-04T13:52:02.077 回答