Skip to content

Instantly share code, notes, and snippets.

@fazlurr
Created January 20, 2015 07:56
Show Gist options
  • Save fazlurr/64f4ea3263ee853ebf76 to your computer and use it in GitHub Desktop.
Save fazlurr/64f4ea3263ee853ebf76 to your computer and use it in GitHub Desktop.
Android SQLite Database Query Method - http://stackoverflow.com/a/10601764
String[] tableColumns = new String[] {
"column1",
"(SELECT max(column1) FROM table2) AS max"
};
String whereClause = "column1 = ? OR column1 = ?";
String[] whereArgs = new String[] {
"value1",
"value2"
};
String orderBy = "column1";
Cursor c = sqLiteDatabase.query("table1", tableColumns, whereClause, whereArgs,
null, null, orderBy);
// since we have a named column we can do
int idx = c.getColumnIndex("max");
String queryString =
"SELECT column1, (SELECT max(column1) FROM table1) AS max FROM table1 " +
"WHERE column1 = ? OR column1 = ? ORDER BY column1";
sqLiteDatabase.rawQuery(queryString, whereArgs);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment