sorting - alphabet sort in mysql -


i using test data "bank" study mysql on mac. have question alphabet sort in mysql.

i have example codeselect cust_id,cust_type_cd,city,state,fed_id customer order 2 asc;

the return shows in column 2, "i" before "b".

anyone knows reason? many thanks.

i guess cust_type_cd enum column "i" ordered before "b" in enum definition.

enums sort ordinal position of value in list defined enumeration, not alphabetical value.

to sort alphabetically, either define enum entries in alphabetical order, or else force value converted string value:

... order concat(cust_type_cd) asc 

see http://dev.mysql.com/doc/refman/5.6/en/enum.html#enum-sorting

note using function in order by clause spoils chance of using index sorting. forced use filesort.


Comments

Popular posts from this blog

C# random value from dictionary and tuple -

cgi - How do I interpret URLs without extension as files rather than missing directories in nginx? -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -