SQL - ORDER BY not working properly?

Try

SELECT test_column 
FROM test_table 
ORDER BY cast(test_column as int)

But you should look into changing the column types to the correct ones.


This work me:-

ORDER BY cast(test_column as SIGNED)

The sort is working. It's a lexicographic sort (alphabetical). It appears that that column has a text (char, varchar, ...) type, so the ordering you'll get is textual and not numeric.

If you want a numerical sort, use a numeric column type (e.g. int). (Or cast the column appropriately.)

Tags:

Sql