Skip to content
Advertisement

How can I use ORDER BY column_string like column_int when my column_string have letters?

I have a table like:

My DB is shared hosted where I don’t have any possibility to set new configurations and, until last week, my query with final ORDER BY animal + 0 ASC was returning the result orderly, like: B1…B5, R1…R72, 1…700. Yesterday our database returned all results, with the same query, disorderly while, in developer DB, it’s returned orderly as always.

I consult the host service, but it affirms there’s no problem with DB and it doesn’t have new configuration.

I tried to use CAST() and CONVERT() function, but it returned animal disorderly.

Can someone shed light on this issue?

Advertisement

Answer

For this sample data this will work:

See the demo.
Results:

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement