mysql order varchar field as integer
mysql, sql, sql-order-by
Solution
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.
Problem
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?