我正在尝试在SQL中进行完全连接,但我一直收到此错误:
You have an error in your SQL syntax; check the ma…yroll P ON A.project_id = P.project_id' at line 1
这是查询。我无法弄清楚出了什么问题!
SELECT A.quantity, A.unit_price, P.paid_amount, FROM assets A FULL JOIN payroll P ON A.project_id = P.project_id
谢谢!
答案 0 :(得分:1)
FULL JOIN
几乎不需要。为什么不这样做?
SELECT A.quantity, A.unit_price, P.paid_amount
FROM assets A LEFT JOIN
payroll P
ON A.project_id = P.project_id;
或者,如果每个表中可能有不同的项目:
SELECT a.quantity, a.unit_price, pr.paid_amount
FROM projects p LEFT JOIN
assets a
ON a.project_id = p.project_id LEFT JOIN
payroll pr
ON a.project_id = p.project_id
WHERE a.project_id IS NOT NULL or pr.project_id IS NOT NULL;
(大概如果你有project_id
,那么你有一个projects
表,每个项目有一行。)
即使在支持FULL JOIN
的数据库中,这两个LEFT JOIN
的效果也可能比FULL JOIN
更好。