mercredi 4 mai 2016

sqlite union all and order by throwing exception

SQLiteQueryBuilder sqLiteQueryBuilder = new SQLiteQueryBuilder();
final String unionQuery = sqLiteQueryBuilder.buildUnionQuery(new String[]{query1, query2, query3}, sortOrder, null);
cursor = db.rawQuery(unionQuery, null);

where query1, query2, query3 are having where clause and are done on same table according to requirement.

Caused by: android.database.sqlite.SQLiteException: 1st ORDER BY term does not match any column in the result set (code 1):

I tried

String finalQuery = "( "+ query1 + " UNION " + query2 + " UNION " + query3 + ") order by " + sortOrder;
cursor = db.rawQuery(unionQuery1, null);

also. and

final String unionQuery1 = "select * from ( "+ unionQuery + ") order by " + sortOrder;

also. But could not get any leads. Please suggest if someone solved the issue.

Aucun commentaire:

Enregistrer un commentaire