MySQL sorts underscores last

I have a column in my table that stores a row (this is a text column):

VARCHAR (16) latin1_swedish_ci

The problem is that when I say "ORDER BY name ASC", it returns words starting with an underscore at the end. This is an example that he returned:

-a
-mmddd2
-z
-z3
aaa
b
c
t
_a
___-

I bet I can use php to sort, but is there an easy way to get mySQL to put underscores after dashes? I do this so that it matches the output of the javascript sorting function.

I am trying to get:

-a
-mmddd2
-z
-z3
_a
___-
aaa
b
c
t
+3
source share
2 answers

Collations , , , , .

+5

, , - :

select name
from customers
order by replace(name, '_', '-+') asc;

+ , .

+1

Source: https://habr.com/ru/post/1716367/


All Articles