OleDb SQL 查询中的两个内部联接
Two Inner Joins in OleDb SQL query
我正在尝试使用 OleDbCommand 对 Access 数据库 (.accdb) 进行 SQL 查询。
虽然此命令工作正常(在 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 ";
另一个没有,我不明白为什么(我看到的所有示例都使用完全相同的语法):
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 ";
给出的异常如下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)
版本和详细信息:
- 数据库是在 Access 2010
上创建的 .accdb
文件
- 连接是在 C# 中创建的
System.Data.OleDb.OleDbConnection
- 连接提供商是
"Microsoft.ACE.OLEDB.12.0"
(这似乎是一个无用的查询,但我当然会添加一个WHERE usr.SOME_FIELD = some_condition
)
"For multi-table joins, you have to nest the extra joins in brackets:"
SQL multiple join statement
我正在尝试使用 OleDbCommand 对 Access 数据库 (.accdb) 进行 SQL 查询。
虽然此命令工作正常(在 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 ";
另一个没有,我不明白为什么(我看到的所有示例都使用完全相同的语法):
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 ";
给出的异常如下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)
版本和详细信息:
- 数据库是在 Access 2010 上创建的
- 连接是在 C# 中创建的
System.Data.OleDb.OleDbConnection
- 连接提供商是
"Microsoft.ACE.OLEDB.12.0"
.accdb
文件
(这似乎是一个无用的查询,但我当然会添加一个WHERE usr.SOME_FIELD = some_condition
)
"For multi-table joins, you have to nest the extra joins in brackets:"
SQL multiple join statement