我正在创建记事本,现在我遇到问题,当我尝试实现连接时动态地将id传入其中并使用Order by。它在“=”附近给出SQLiteexception。
我不知道我写这个查询的原因是什么:
String selectQuery = "SELECT " + KEY_TASKNOTE + " FROM " + TABLE_TODOTASK
+ " INNER JOIN" + TABLE_TODOTASK_DETAILS + "ON " + KEY_TASKID + "=" + KEY_TASK_DETAILS_TASKID + " WHERE "
+ KEY_TASK_TASKLISTID + "=" + tasklist_Id + " ORDER BY " + KEY_TASK_DETAILS_DUEDATE;
常量:
// TASK table name
private static final String TABLE_TODOTASK = "todotask";
// TASKLIST Table Columns names
private static final String KEY_TASKID = "Id";
private static final String KEY_TASKNOTE = "tasknote";
private static final String KEY_TASKDUEDATE = "duedate";
private static final String KEY_TASKCOMPLETED = "taskcompleted";
private static final String KEY_TASK_TASKLISTID = "TaskList_id";
// TASKDETAILS table name
private static final String TABLE_TODOTASK_DETAILS = "todotaskdetails";
// TASKDETAILS Table Columns names
private static final String KEY_TASK_DETAILS_ID = "ID";
private static final String KEY_TASK_DETAILS_TASKID = "Task_id";
private static final String KEY_TASK_DETAILS_DUEDATE = "taskduedate";
private static final String KEY_TASK_DETAILS_EVENT = "taskevent";
private static final String KEY_TASKDETAILS_REMINDER = "taskreminder";
private static final String KEY_TASKDETAILS_REPEAT = "taskrepeat";
private static final String KEY_TASKDETAILS_PRIORITY = "taskpriority";
请帮忙,谢谢
答案 0 :(得分:0)
对于内部联接,您需要使用tablename1.fieldName = tablename2.fieldName
,但仅使用field name = field name
。添加如下表格前缀:
String selectQuery = "SELECT " + KEY_TASKNOTE + " FROM " + TABLE_TODOTASK
+ " INNER JOIN " + TABLE_TODOTASK_DETAILS + " ON " + TABLE_TODOTASK+"."+KEY_TASKID + "=" + TABLE_TODOTASK_DETAILS +"."+KEY_TASK_DETAILS_TASKID + " WHERE "
+ KEY_TASK_TASKLISTID + "=" + tasklist_Id + " ORDER BY " + KEY_TASK_DETAILS_DUEDATE;
内连接的简单示例
SELECT column_name(s)
FROM table_name1
INNER JOIN table_name2
ON table_name1.column_name=table_name2.column_name