How to get maximum data using natural sorting?

10.12.1 
10.12.10 
10.12.11 
10.12.12 
10.12.13 
10.12.14 
10.12.15 
10.12.16 
10.12.17 
10.12.18 
10.12.19 
10.12.2 
10.12.3 
10.12.4 
10.12.5 
10.12.6 
10.12.7 
10.12.8 
10.12.9 

This is a varchar column. But '10 .12.19 'is the maximum data I need. How can i get it?

+3
source share
2 answers

SQL code

 ORDER BY CAST(SUBSTRING_INDEX(col,'.',-1) AS SIGNED) DESC;
+4
source

MySQL doesn't have a natural sort yet. This has been an open function request since 2003: http://bugs.mysql.com/bug.php?id=1588

I would do this outside of SQL or change the values ​​(or add a new column) so that the numbers are fixed width.

0
source

Source: https://habr.com/ru/post/1711309/


All Articles