1

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

Himanshu
  • 31,810
  • 31
  • 111
  • 133
littleblue
  • 41
  • 6

1 Answers1

4

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

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

SQLFiddle demo

juergen d
  • 201,996
  • 37
  • 293
  • 362
  • Works fine thanks. How would you put this statement in php mysql_query? – littleblue Apr 29 '13 at 12:26
  • 1
    Please, [don't use mysql_* functions in new code](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php). They are no longer maintained and are [officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). Learn about **Prepared Statements** instead, and use [PDO](http://php.net/pdo) or [MySQLi](http://php.net/mysqli). See [this article](http://stackoverflow.com/questions/60174/best-way-to-prevent-sql-injection-in-php) for a quick overview how to do it and why it is so important. – juergen d Apr 29 '13 at 12:33