Reputation: 2335
I have a "Location" data set returned by a simple query from a MySQL database:
A1
A10,
A2
A3
It is sequenced by an "Order By Location" statement. The issue is that I would like the returned sequence to be:
A1
A2
A3
A10
I am not sure if this is achievable with a MySQL Order By statement?
Upvotes: 0
Views: 162
Reputation: 37233
try this
order by CAST(replace((Location),'A','') as signed )
EDIT:
if you have other letters then A then consider to cut the first letter and order the rest as integers.
ORDER BY CAST(SUBSTR(loc, 2) as signed )
Upvotes: 1
Reputation: 1269773
I think the easiest way to do this is to order by the length and then the value:
order by length(location), location
Upvotes: 2