Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 577
Migol Avatar asked May 25 '09 13:05

Migol


People also ask

How do you select the highest value in a column in SQL?

To find the max value of a column, use the MAX() aggregate function; it takes as its argument the name of the column for which you want to find the maximum value. If you have not specified any other columns in the SELECT clause, the maximum will be calculated for all records in the table.

How do I find the maximum value of a column in MySQL?

The MySQL Solution If you're working with MySQL, you can combine MAX() with the GREATEST() function to get the biggest value from two or more fields. Here's the syntax for GREATEST: GREATEST(value1,value2,...) Given two or more arguments, it returns the largest (maximum-valued) argument.

How do I get the maximum value from another column of a table in SQL?

If you want to understand VALUE try this query which creates a virtual 1 column table: SELECT * FROM (VALUES (1), (5), (1)) as listOfValues(columnName) And this query which creates a virtual 2 column table: SELECT * FROM (VALUES (1,2), (5,3), (1,4)) as tableOfValues(columnName1, ColumnName2) Now you can understand why ...


1 Answers

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.

like image 153
Reto Meier Avatar answered Sep 20 '22 11:09

Reto Meier