Reputation: 17997
How to ORDER BY a field consisting of digits following by alphabets, such as 10s
, in MySQL? The desired order is:
10
10s
For instance,
# Original data:
1
10
105
109
10s
# Desired results
1
10
10s
105
109
Upvotes: 1
Views: 51
Reputation: 106365
One possible approach:
ORDER BY CAST(alphanum AS UNSIGNED), alphanum
... or, slightly more concise:
ORDER BY alphanum + 0, alphanum
Demo.
Upvotes: 1
Reputation: 1135
Try this:
SELECT values FROM Table ORDER BY CAST(values AS UNSIGNED), values;
Upvotes: 2