ahmed galal ahmed galal - 4 months ago 13
SQL Question

Order by varchar stored as number giving wrong output

i'm trying a simple select query but the output is totally wrong , mainly it's a laravel project but i tried the sql on phpmyadmin and the error still the same

enter image description here

any help would be great , thank you.


If the datatype of property_price is VARCHAR

SELECT * FROM properties ORDER BY property_price+0 ASC LIMIT 10;


SELECT * FROM properties ORDER BY CAST(property_price AS UNSIGNED) ASC LIMIT 10;


Change the datatype of property_price column to a numeric type.