Order by leading digits

from the Artful Common Queries page


To have column values 1abc,10abc,8abc appear in the expected order 1abc,8abc,10abc, take advantage of a trick built into MySQL string parsing ...


SELECT '3xyz'+0;

+----------+

| '3xyz'+0 |

+----------+

|        3 |

+----------+



to write ...


SELECT ...

...

ORDER BY colname+0, colname;




Return to the Artful Common Queries page