How to use rawQuery () in android

I have sql query like this

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);

      

I got an error running this request. Correct structure? Can anyone help me?

+2


source to share


1 answer


Always troubleshoot errors by looking at the SQL string, not the code that builds the SQL string!

SELECT _id, title, name, favorite FROM table1 where favorite= 1 UNION ALLSELECT _id, title, name, favorite FROM table2 where favorite= 1

      



You will need a space between ALL

and the second SELECT

.

+8


source







All Articles