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
Post a Comment