tags:

views:

88

answers:

2
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 max data i need. How can i get it?

+3  A: 

SQL code

 ORDER BY CAST(SUBSTRING_INDEX(col,'.',-1) AS SIGNED) DESC;
ZA
If the data changed to include 10.13.1, this statement would no longer work as required. It is not a general solution to the problem, in other words.
Jonathan Leffler
A: 

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

I'd do it outside of SQL, or change the values (or add a new column) so that the numbers are fixed width.

David