Search code examples
sqlsqlitemaxaggregate-functions

Select the row with maximum/minimum value in SQLite


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?


Solution

  • According to the docs, SQLite allows to select the entire row with max():

    SELECT *, max(a) FROM MyTable;
    

    (This is supported since version 3.7.11.)