我有这样的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);
运行此查询时出现错误。结构正确吗?有人能帮我吗?
始终通过查看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。
ALL
SELECT