tags:

views:

1312

answers:

1

Hi, I have a 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 when run this query. Is it right structure? Can someone help me?

+1  A: 

Always troubleshoot 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 need a space between ALL and the second SELECT.

Bill Karwin
Oh! I break my query because it too long on the screen, and I forgot about the "space"! Thank you so much!
Dennie
Yeah, it's unfortunate that Java doesn't permit string literals to span lines. It leads to this common type of mistake.
Bill Karwin