The query…
select distinct name from myTable
returns a bunch of values that start with the following character sequences…
ADL*
FG*
FH*
LAS*
TWUP*
Where ‘*’ is the remainder of the string.
I want to do an order by that sorts in the following manner…
ADL*
LAS*
TWUP*
FG*
FH*
But then I also want to sort within each name in the standard order by fashion. So, an example, if I have the following values
LAS-21A
TWUP-1
FG999
FH3
ADL99999
ADL88888
ADL77777
LAS2
I want it to be sorted like this…
ADL77777
ADL88888
ADL99999
LAS2
TWUP-1
FG999
FH3
I initially thought I could accomplish this vias doing an order by decode(blah) with some like trickery inside of the decode but I’ve been unable to accomplish it. Any insights?
Goofy and verbose, but should work:
Not sure if 6 is the correct place to sort the other items, but it is obvious how to fix that. At least it is clear what is going on, even if I have no idea why you are doing it this way.
EDIT: If these are the only values, you could change lines 4 and 5:
ANOTHER EDIT: And again, if these are the only values, you can simplify even more. Since the only one out of order is the F* series, you can force them to the end, and use the actual first letter for all the others. This is simpler, but relies too much on the exact values for my preference. On the other hand, it does remove many of the seemingly unnecessary calls to
substr: