admin

如何在Android中使用rawQuery()

sql

我有这样的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);

运行此查询时出现错误。结构正确吗?有人能帮我吗?


阅读 175

收藏
2021-06-07

共1个答案

admin

始终通过查看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

2021-06-07