How Should This SQL with Left Joins be Written in Access 2007?

五迷三道 提交于 2020-01-06 16:39:27

问题


I have a sql statement with multiple left joins that I cannot get to work in Access 2007, the message stating,

JOIN expression not supported

SELECT
  Foo.A,
  Bar.B,
  Baz.C,
  Bat.D
FROM
  Foo
LEFT JOIN
  Bar ON Foo.BarId = Bar.BarId
LEFT JOIN
  Baz ON Foo.BazId = Baz.BazId
LEFT JOIN
  Bat ON Foo.BatId = Bat.BatId

WHERE 
  Foo.CriteriaColumn = 1

What is the correct format for Access 2007?


回答1:


It's been a while since I did joins in Access, but enclosing each join expression separately in parentheses should do the trick:

SELECT
  Foo.A,
  Bar.B,
  Baz.C,
  Bat.D
FROM
  ((Foo
LEFT JOIN
  Bar ON Foo.BarId = Bar.BarId)
LEFT JOIN
  Baz ON Foo.BazId = Baz.BazId)
LEFT JOIN
  Bat ON Foo.BatId = Bat.BatId
WHERE 
  Foo.CriteriaColumn = 1


来源:https://stackoverflow.com/questions/1527752/how-should-this-sql-with-left-joins-be-written-in-access-2007

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!