How in MySql to extract the maximum value from a field with the type text?

id | value
1 | 3
2 | 24
3 | -5
4 | 2
5 | 200
6 | 99

SELECT MAX(value) FROM `test`
Gives 99, and should be 200
July 2nd 19 at 17:38
2 answers
July 2nd 19 at 17:40
Solution
Try like this:

SELECT MAX(CAST(value AS UNSIGNED)) FROM `test`
Gives 18446744073709551611 - kelsi.Lango commented on July 2nd 19 at 17:43
then use SIGNED - Khalid59 commented on July 2nd 19 at 17:46
SELECT MAX(CAST(value AS SIGNED)) FROM `test` - Rosalind_Luettgen commented on July 2nd 19 at 17:49
July 2nd 19 at 17:42
200 > 99
'99' > '200'
How can I solve my problem? As it is necessary to cast the values to numeric type? - kelsi.Lango commented on July 2nd 19 at 17:45
: CAST() or CONVERT() - Khalid59 commented on July 2nd 19 at 17:48

Find more questions by tags SQLMySQL