用WHERE子句更新JOIN另一个表

时间:2019-06-10 14:57:28

标签: java android sqlite sqliteopenhelper

我有下表:

习惯

ID INT PRIMARY KEY

NUMBER INT FOREIGN KEY

DATE DATE

DONE BOOL


HABIT_DESCRIPTION

NUMBER INT PRIMARY KEY

NAME VARCHAR

DESCRIPTION VARCHAR

我要对HABIT中特定行进行更新,其中HABIT_DESCRIPTION的名称为

我尝试过:

ContentValues cv = new ContentValues();
    cv.put(HABIT_COL_DONE, true);
    String whereclause = HABIT_DESCRIPTION_NAME+ "='water'";
    return db.update("HABIT",cv,whereclause,null);

1 个答案:

答案 0 :(得分:0)

由于 SQLite 不支持UPDATE语句中的联接,因此可以使用EXISTS

String whereclause = 
    "EXISTS (SELECT 1 FROM HABIT_DESCRIPTION WHERE NUMBER = HABIT.NUMBER AND DESCRIPTION = ?)";
String param = "water";
return db.update("HABIT", cv, whereclause, new String[] {param});