So i have a table with a VARCHAR field. It is used to sort a lot of decimals value:
Let's say i have the following entries in my VARCHAR field:
Let's say I want to display all entries using ORDER BY varchar DESC. The result would be:
When obviously 263.28 should be the first one. What's wrong ?
If you have all decimal values in varchar field then just convert it to decimal and then apply order by clause. I have not much idea about mysql data type and convert function, but in MS SQL you can convert it to decimal like
ORDER BY CAST(field AS DECIMAL(18,2)) DESC
UPDATE :
Yes, in MySQL also there is cast function : http://dev.mysql.com/doc/refman/5.0/en/cast-functions.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With