1

这个查询

SELECT * 
FROM tblContracts 
LEFT JOIN tblPartys ON tblContracts.id = tblPartys.Contract_id 
INNER JOIN tblAdministrators 
        ON tblContracts.AdministratorID = tblAdministrators.ID

适用于 mysql 数据库,但不适用于 Access DB !!!

我收到这个错误打击:

System.Data.OleDb.OleDbException:查询表达式“tblContracts.id = tblPartys.Contract_id INNER JOIN tblAdministrators ON tblContracts.AdministratorID = tblAdministrators.I”中的语法错误(缺少运算符)。在 System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(OleDbHResult hr) 在 System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult) 在 System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult) 在 System.Data。 System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior 行为,String 方法)处 System.Data.OleDb.OleDbCommand.ExecuteReader(CommandBehavior 行为)处的 OleDb.OleDbCommand.ExecuteCommand(CommandBehavior 行为,Object& executeResult)

4

3 回答 3

1

尝试在第一个连接周围添加几个括号

SELECT * 
FROM (tblContracts 
LEFT JOIN tblPartys ON tblContracts.id = tblPartys.Contract_id) 
INNER JOIN tblAdministrators 
        ON tblContracts.AdministratorID = tblAdministrators.ID
于 2012-06-28T14:21:52.720 回答
0

尝试这个:

  SELECT *  FROM ((tblContracts 
   LEFT JOIN tblPartys ON tblContracts.id = tblPartys.Contract_id ) 
     INNER JOIN tblAdministrators ON tblContracts.AdministratorID = tblAdministrators.ID )  

以我的经验,Access 喜欢括号……有点太多了,如果你问我的话。

于 2012-06-28T18:54:26.623 回答
0

根据您发布的错误,您误ON tblContracts.AdministratorID = tblAdministrators.ID写成ON tblContracts.AdministratorID = tblAdministrators.I解释:

查询表达式“tblContracts.id = tblPartys.Contract_id INNER JOIN tblAdministrators ON tblContracts.AdministratorID = tblAdministrators.I”中的语法错误(缺少运算符)。在 ...

所以确保它写成ON tblContracts.AdministratorID = tblAdministrators.ID

于 2012-06-28T14:21:21.817 回答