Two Inner Joins in OleDb SQL query [duplicate]

人走茶凉 提交于 2021-01-27 13:30:35

问题


I'm trying to make an SQL query with an OleDbCommand into an Access database (.accdb).

While this command works fine (in a OleDbCommand.ExecuteReader()):

string command =
   "SELECT cred.* " +
   "FROM TB_CREDENTIALS cred " +
   "INNER JOIN TB_REL_USERS_CREDENTIALS rel ON cred.CRED_ID = rel.REL_USR_CRED_CRED_ID ";

This other doesn't, and I can't understand why (all examples I see around use the exact same syntax):

string command =
   "SELECT cred.* " +
   "FROM TB_CREDENTIALS cred " +
   "INNER JOIN TB_REL_USERS_CREDENTIALS rel ON cred.CRED_ID = rel.REL_USR_CRED_CRED_ID " +
   "INNER JOIN TB_USERS usr ON usr.USR_ID = rel.REL_USR_CRED_USER_ID ";

The exception given is the following System.Data.OleDb.OleDbException:

Syntax error (missing operator) in query expression 'cred.CRED_ID = rel.REL_USR_CRED_CRED_ID INNER JOIN TB_USERS usr ON usr.USR_ID = rel.REL_USR_CRED_USER_I' (message is cut here)

Version and details:

  • The database is a .accdb file created on Access 2010
  • The connection is created in C# with System.Data.OleDb.OleDbConnection
  • The connection provider is "Microsoft.ACE.OLEDB.12.0"

(This seems like a useless query, but of course I'll add a WHERE usr.SOME_FIELD = some_condition)


回答1:


"For multi-table joins, you have to nest the extra joins in brackets:"

SQL multiple join statement



来源:https://stackoverflow.com/questions/48996543/two-inner-joins-in-oledb-sql-query

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