Search code examples
sqldatabaseandroidaggregate

Android: Get highest value in column


I have an URL pointing to content and I need to get the highest value contained in one of the columns. Is there any aggregate function that will accomplish that or do I have to do this manually?


Solution

  • If you're querying an Android content provider, you should be able to achieve this by passing MAX(COLUMN_NAME) in to the selection parameter of ContentResolver.query:

    getContentResolver().query(uri, projection, "MAX(COLUMN_NAME)", null, sortOrder);
    

    Where Uri is the address of the content provider. This should return the single row with the highest value in COLUMN_NAME.