Android SQLite Syntax for max value in a field

android, sqlite

Solution

It seems that `GAMES_TABLE` & `GAME_COLUMN` is variable of String type.

if those are variable then you have to write query like

`"SELECT MAX("+GAME_COLUMN+") FROM "+GAMES_TABLE`

It is better to use query instead of rawQuery like below

db.query(GAMES_TABLE, new String [] {"MAX("+GAME_COLUMN+")"}, null, null, null, null, null);

Problem

Trying to get the maximum value in a column via an SQLite query. From everything that I am reading my code should work. But it doesn't. Here is the code: ``` SQLiteDatabase db = myDBOpenHelper.getWritableDatabase(); Cursor cursor = db.rawQuery("SELECT MAX(GAME_COLUMN) FROM GAMES_TABLE", null); ``` The table is empty at this point, not that I think it should matter. Here is the error: sqlite returned: error code = 1, msg = near "null": syntax error I must be writing this incorrectly, but I don't see the mistake. The table and column names are entered corectly. Can anybody spot this? Apologies in advance if I'm overlooking something stupid. Pretty new to SQLite. Thanks!

Original source