Home > Mobile >  How to get the latest version number from a sql table
How to get the latest version number from a sql table

Time:12-29

I have a sql table and it contain the list of version number, how to get the latest version number ?

id Version number
1 2.1.0
2 1.2.1
3 1.1.3

how will i get the latest version '2.1.0' from the table by executing a sql query.

CodePudding user response:

In Postgres you can convert the version number to an integer array, then use the max() function:

select max(string_to_array(version_number, '.')::int[])
from the_table;

Alternatively if you want the whole row, you can use:

select *
from the_table
order by string_to_array(version_number, '.')::int[] desc
limit 1;
  • Related