mysql order varchar field as integer
I have a varchar field in my table and I want to sort it. But I need to handle this field as integer. Meaning if sort as text the order is "19,2,20" but I want to get the right order "2,19,20". Can anyone help me? I somehow didn't manage to run the query with CAST . I was always getting Error Code: 1064 near "DECIMAL" (or other numeric type that I chose). So, I found another way to sort varchar as numbers: SELECT * FROM mytable ORDER BY ABS(mycol) A bit simpler and works in my case. SELECT * FROM mytable ORDER BY CAST(mycol AS DECIMAL) Here is the solution SELECT * FROM MyTable ORDER BY ABS