Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Two Inner Joins in OleDb SQL query [duplicate]

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)

like image 949
Daniel Möller Avatar asked Oct 16 '25 09:10

Daniel Möller


1 Answers

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

SQL multiple join statement

like image 84
GeorgiG Avatar answered Oct 17 '25 22:10

GeorgiG



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!