我有像这样的SQL查询
String loadFav = "SELECT _id, title, name, favorite FROM table1 where favorite= 1 "
+ "UNION ALL"
+ "SELECT _id, title, name, favorite FROM table2 where favorite= 1"
;
Cursor mCursor = mSQLiteDatabase.rawQuery(loadFav, null);
运行此查询时出错。这是正确的结构吗?有人能帮助我吗?
答案 0 :(得分:8)
始终通过查看SQL字符串进行故障排除 - 而不是构建SQL字符串的代码!
SELECT _id, title, name, favorite FROM table1 where favorite= 1 UNION ALLSELECT _id, title, name, favorite FROM table2 where favorite= 1
ALL
和第二个SELECT
之间需要一个空格。