我的数据库包含几个查找表(在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'
导致此错误的原因是什么?
答案 0 :(得分:1)
Access需要多个连接的括号。例如:
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
答案 1 :(得分:1)
访问对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