Created
January 20, 2015 07:56
-
-
Save fazlurr/64f4ea3263ee853ebf76 to your computer and use it in GitHub Desktop.
Android SQLite Database Query Method - http://stackoverflow.com/a/10601764
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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