为什么我在“WHERE”附近的查询中出现语法错误? (多个表格)
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了为什么我在“WHERE”附近的查询中出现语法错误? (多个表格)相关的知识,希望对你有一定的参考价值。
我还是新手,这是我第一次使用这些多表查询。为什么我会出现这样的错误?这是我的代码:
String selectQuery =
" select *" +
" from tableassign left outer join\n" +
" tableacc\n" +
" on tableassign.signeeid = tableacc.userid left outer join\n" +
" tableinfo\n" +
" on tableassign.signeeid = tableinfo.userid left outer join\n" +
" WHERE tableassign.signeedepid =?";
Cursor data = db.rawQuery(selectQuery , new String[]{ signeedep });
错误:
android.database.sqlite.SQLiteException: near "WHERE": syntax error (code 1):
, while compiling: select * from tableassign left outer join tableacc on
tableassign.signeeid = tableacc.userid left outer join tableinfo on
tableassign.signeeid = tableinfo.userid left outer join WHERE
tableassign.signeedepid =?
答案
看来你有一个复制/粘贴问题。删除left outer join
之前的最后一个where
:
String selectQuery =
" select *" +
" from tableassign left outer join\n" +
" tableacc\n" +
" on tableassign.signeeid = tableacc.userid left outer join\n" +
" tableinfo\n" +
" on tableassign.signeeid = tableinfo.userid\n" +
" WHERE tableassign.signeedepid =?";
Cursor data = db.rawQuery(selectQuery , new String[]{ signeedep });
我的格式有点不同,主要是为了便于阅读:
String selectQuery =
" SELECT *\n" +
" FROM tableassign\n" +
" LEFT JOIN tableacc ON tableassign.signeeid = tableacc.userid\n" +
" LEFT JOIN tableinfo ON tableassign.signeeid = tableinfo.userid\n" +
" WHERE tableassign.signeedepid =?";
Cursor data = db.rawQuery(selectQuery , new String[]{ signeedep });
另一答案
虽然我不确定您正在使用哪种结构化语言进行查询,但问题似乎在于您使用JOIN运算符。有关LEFT OUTER JOIN的Oracle文档显示了它的正确用法,其语法为:
TableExpression LEFT [ OUTER ] JOIN TableExpression
{
ON booleanExpression |
USING clause
}
最后的LEFT OUTER JOIN紧接在WHERE子句之前,而没有定义TableExpression。删除LEFT OUTER JOIN子句以删除错误。
String selectQuery =
" select *" +
" from tableassign left outer join\n" +
" tableacc\n" +
" on tableassign.signeeid = tableacc.userid left outer join\n" +
" tableinfo\n" +
" on tableassign.signeeid = tableinfo.userid" +
" WHERE tableassign.signeedepid =?";
Cursor data = db.rawQuery(selectQuery , new String[]{ signeedep });
以上是关于为什么我在“WHERE”附近的查询中出现语法错误? (多个表格)的主要内容,如果未能解决你的问题,请参考以下文章
在关键字“pivot”附近出现语法错误,提示语法不正确。我在这里想念啥
带有 dapper 和 postgresql 的“WHERE x IN y”子句抛出 42601:在 \"$1\" 处或附近出现语法错误
查询错误(1064):'INTERSECT附近的语法错误(SELECT friend_id FROM user_friend_list WHERE user_id ='20'和