Hello i am trying to order by in mysql by sorting
- Special characters
- Letters
- then Numbers
it seems like mysql sorts by
- Special Characters
- Numbers
- then Letters
See below
select distinct uag_linecode from part order by uag_linecode;
| A-1 |
| A/C |
| A1S | out of place
| ABP |
| ABS |
| ACI |
| ADM |
| ADR |
| BAS |
This is what i want:
A-1
A/C
ABR
ABS
ACI
ADM
ADR
A1S correct spot
BAS
If anyone can help me out i would be eternally grateful.
All the line codes are always 3 characters long.
Something like this would work if it were always the 2nd character — you might be able to add to the case clause to check for 1st and 3rd characters…
Here is the SQL Fiddle.
–EDIT
This appears to work for 1st and 3rd characters as well:
And more Fiddle.
Also as @Orbling correctly says, you’ll get a better performance (especially if you have lots of records) to remove the REDEXP and use >= ‘0’ AND <= ‘9’.
Good luck.