0

I have a table with a varchar field, in which there is alphanumeric data like following:

       RANDOM_ID

       Doc2
       SOP1
       SOP2
       SOP8
       AOP15
       AOP89
       SOP90
       SOP100
       SOP158
       TASK6
       TASK56
       TEST5
       TEST15

I tried with ORDER BY LENGTH() but it's not working for ASC and DESC both

Exacted for

ORDER BY ASC           ORDER BY DESC

AOP15                    TEST15
AOP89                    TEST5
Doc2                     TASK56
SOP1                     TASK6
SOP2                     SOP158
SOP8                     SOP100
SOP90                    SOP90
SOP100                   SOP8
SOP158                   SOP2
TASK6                    SOP1
TASK56                   Doc2
TEST5                    AOP89
TEST15                   AOP15

Thanks in advance

  • Duplicate of https://stackoverflow.com/questions/8557172/mysql-order-by-sorting-alphanumeric-correctly – gargkshitiz Jan 20 '18 at 10:53
  • 1
    There is no easy way to sort this column in MySQL. The easiest way to do this would be to remove alphas/numbers and sort on each. If you make the column fixed width, it should sort properly. – Tim Biegeleisen Jan 20 '18 at 10:55
  • I already tried with this https://stackoverflow.com/questions/8557172/mysql-order-by-sorting-alphanumeric-correctly solution but it's not working for my case –  Jan 20 '18 at 10:58
  • Garbage in, garbage out, I'm afraid – Strawberry Jan 20 '18 at 11:01

0 Answers0