mysql - order by a certain character -



mysql - order by a certain character -

let's suppose have table containing 'name' column next rows:

'a' 'k' '_c' '_b'

is there way order alphabetically , placing names come underscore '_' first (alphabetically too) using order on mysql? output be:

'_b' '_c' 'a' 'k'

order case when substr(mystring, 0,1) = '_' 0 else 1 end , mystring

(not tested, idea)

i.e. first order on whether or not string starts character '_' or not, , on string itself.

as others have pointed out, illustration renders unecessary, how in general. instance, order 5-character words first in similar way:

order case when length(mystring) = 5 0 else 1 end , mystring

mysql sql sql-order-by

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -