在我的应用程序中,我需要连接两个表,并且我已经使用了这段代码:
Cursor shapes_cur = sq.getWritableDatabase().rawQuery("SELECT name from shapes INNER JOIN shapes ON shape_to_drug.id_shape=shapes.id WHERE shape_to_drug.id_drug =" + drug_id + " WHERE shape_to_drug.id_hp =" + hp_id, null);
但是申请人关闭了,我在logcat中得到了这个错误:
android.database.sqlite.SQLiteException: near "WHERE": syntax error (code 1): , while compiling: SELECT name from shapes INNER JOIN shapes ON shape_to_drug.id_shape=shapes.id WHERE shape_to_drug.id_drug =360 WHERE shape_to_drug.id_hp =5
答案 0 :(得分:4)
您的查询中有两个WHERE子句,您应该使用AND:
"SELECT s.name from shapes s INNER JOIN shapes shape_to_drug ON shape_to_drug.id_shape=s.id WHERE shape_to_drug.id_drug =" + drug_id + " AND shape_to_drug.id_hp =" + hp_id