Mega Code Archive

 
Categories / MySQL Tutorial / Cast Functions Operators
 

CAST() is useful for sorting ENUM columns in lexical order

Normally, sorting of ENUM columns occurs using the internal numeric values. Casting the values to CHAR results in a lexical sort: mysql> mysql> SELECT enum_col FROM tbl_name ORDER BY CAST(enum_col AS CHAR); mysql>