Search code examples
mysqlsqlmaxvarchar

Max numeric valu of a varchar Column


Below is my cloumn from mytable and it is VARCHAR. The values are coming in a txt file from a weather station. Using PHP all the values are imported into a Mysql DB. I need to select the max value from Outside which is (11,5) . How can I do it?

Outside
-------
9,5
9,9
10,3
10,2
11,5
11,3

I tried

SELECT MAX( CONVERT( Outside, UNSIGNED ) )

This gives only 11


Solution

  • Replace the , with . and use the auto convertion when multiplicating with a decimal number

    SELECT max(replace(Outside, ',', '.') * 1.0)  
    

    SQLFiddle demo