4

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)

3
  • Please validate my answer if it helped you. Commented Feb 26, 2018 at 20:36
  • Of course :) -- Waiting for the time limit. Commented Feb 26, 2018 at 20:37
  • Sorry, you are right! And thank you. I am new to answering questions. Commented Feb 26, 2018 at 20:46

1 Answer 1

3

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

SQL multiple join statement

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.