Search code examples
mysqlcolumnsorting

Sorting in MySQL in a specific manner in one column


So I have a data where one of the column (section) contains the following:
A1LB
A1LC
A1RC
A2LB
A2LC
A2RC
B1LB
B1LC

but I want the data to look like this:
A1LC
A1LB
A1RC
A2LC
A2LB
A2RC
B1LC
B1LB

I have tried "ORDER BY CASE WHEN section like %LC" THEN 1 else 2 END" but it comes out with all of the LCs on top
A1LC
A2LC
B1LC
B2LC
A1LB
A1RC
A2LB
A2RC
B1LB
B1RC

how can I do so without having all of the LC's on top but in the order I want it to be?


Solution

  • Looks like:

    ORDER BY substring(section, 1, 3), substring(section, 4, 1) desc