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

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

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