Select the row with maximum/minimum value in SQLite

Viewed 6730

According to the docs, common sense and some manuals on common SQL the max function returns only maximum value. So the correct way to select the row(s) with the maximum value is a subquery:

select * from `table` where `a`=(select max(`a`) from `table`);

It's inefficient. Are there something like argmax in SQLite?

5 Answers

Please check the below query for max and min value for your choice row.

The query for max value in a row:

SELECT max(timestamp) FROM tableName 

The query for min value in a row:

SELECT min(timestamp) FROM tableName 

Note: timestamp is row name in the table. You can use where you want to apply.

Related