使用多个左连接的MS Access SQL

时间:2013-03-27 10:09:58

标签: ms-access

以下联接在Access中有效,但我需要添加第四个联接。

FROM ((Agents
LEFT JOIN Resignation_Pool    ON Agents.PF = Resignation_Pool.PF)
LEFT JOIN Teams               ON Agents.Team = Teams.ID)
LEFT JOIN Skills              ON Agents.PF = Skills.PF

当我添加第四个连接时,它不起作用。我知道Access的括号很奇怪,但我认为我有它们所属的地方。查询只是永远不运行(它应该不会长时间运行),我最终取消它。有什么建议吗?

FROM (((Agents
LEFT JOIN Resignation_Pool    ON Agents.PF = Resignation_Pool.PF)
LEFT JOIN Teams               ON Agents.Team = Teams.ID)
LEFT JOIN Skills              ON Agents.PF = Skills.PF)
LEFT JOIN OneMore             ON Agents.OM = OneMore.OM

这是可行的代码 - 我的实际查询而不是我发现的类似的查询。

SELECT DISTINCT A02.PID, A02.PS, A02.PN, A02.PM, C01.RC, C01.IC, C01.RD 
INTO AutoCR 
FROM ((02_CorrectResults A02 
LEFT OUTER JOIN dbo_pol_PGI C01 
  ON (A02.PID = C01.PID and C01.PS = '999' and C01.PEDate >= #04/01/2012#)) 
LEFT OUTER JOIN dbo_pol_IL C02 
  ON C01.PID = C02.PID) 
LEFT OUTER JOIN dbo_pol_UN C03 
  ON C02.ILID = C03.ILID

我添加了另一个连接,但这不起作用。我尝试使用内部连接,但Access不喜欢这样。

SELECT DISTINCT A02.PID
, A02.PS
, A02.PN
, A02.PM
, C01.RC
, C01.IC
, C01.RD
, C04.CCode
, C04.PCode
, C04.CForm,
INTO AutoCR 
FROM (((02_CorrectResults A02 
LEFT OUTER JOIN dbo_rol_PGI C01 
  ON (A02.PID = C01.PID and C01.PS = '999' and C01.PEDate >= #04/01/2012#)) 
LEFT OUTER JOIN dbo_rol_IL C02 
  ON C01.PID = C02.PID) 
LEFT OUTER JOIN dbo_rol_UN C03 
  ON C02.ILID = C03.ILID) 
LEFT OUTER JOIN dbo_rol_HO C04 
  ON C03.UnID = C04.UnID

1 个答案:

答案 0 :(得分:6)

您的查询中有一个尾随,。去掉它。

SELECT DISTINCT A02.PID
, A02.PS
, A02.PN
, A02.PM
, C01.RC
, C01.IC
, C01.RD
, C04.CCode
, C04.PCode
, C04.CForm,   <--- this was the problem
INTO AutoCR 
FROM (((02_CorrectResults A02 
LEFT OUTER JOIN dbo_rol_PGI C01 
  ON (A02.PID = C01.PID and C01.PS = '999' and C01.PEDate >= #04/01/2012#)) 
LEFT OUTER JOIN dbo_rol_IL C02 
  ON C01.PID = C02.PID) 
LEFT OUTER JOIN dbo_rol_UN C03 
  ON C02.ILID = C03.ILID) 
LEFT OUTER JOIN dbo_rol_HO C04 
  ON C03.UnID = C04.UnID