简体   繁体   English

MS ACCESS SQL连接语法

[英]MS ACCESS SQL Join Syntax

I can get this query to run if I remove the Join, but once I add the join, I get the following error: 如果删除联接,则可以使该查询运行,但是一旦添加联接,就会出现以下错误:

Run-Time error '3135': Syntax error in Join Operation 运行时错误“ 3135”:连接操作中的语法错误

sourceDB = "C:\sourcedb.accdb"

SQL = "SELECT e1.lid " & _
        "FROM (eventlog e1 IN  '" & sourceDB & "'" & _
        "LEFT JOIN eventlog e2 ON e2.lid = e1.lid)"

Any advice on what I might be doing wrong 关于我可能做错了什么的任何建议

Try changing your code to the following: 尝试将代码更改为以下内容:

sourceDB = "C:\sourcedb.accdb"

SQL = "SELECT e1.lid " & _
      "FROM [" & sourceDB & "].[eventlog] AS e1 " & _
      "LEFT JOIN eventlog AS e2 ON e2.lid = e1.lid"

You have an obvious syntax error in your query: the join must be between two Tables, not the Table and Database name. 查询中有一个明显的语法错误:连接必须在两个表之间,而不是表和数据库名称之间。 Take a look at this canonical example (re: https://msdn.microsoft.com/en-us/library/office/ff198084.aspx ) and correct your query correspondingly: 看一下这个规范示例(请参阅: https : //msdn.microsoft.com/zh-cn/library/office/ff198084.aspx ),并相应地更正您的查询:

SELECT CategoryName, ProductName FROM Categories LEFT JOIN Products 
ON Categories.CategoryID = Products.CategoryID;

Hope this will help. 希望这会有所帮助。 Best regards, 最好的祝福,

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM