Sort by value of ENUM MySql

0

I have a question and since I did not find anything on the internet I decided to ask you, well, I have a MySql table and this table contains an ENUM field that can be 'yes' or 'no', I wonder if it is possible to sort the results for those values, like this

SELECT * FROM tabela ORDER BY tabela.coluna = 'nao'

In order for the displayed values to not appear first, the problem is that I can not make it work with codeigniter, what do I do?

    
asked by anonymous 25.02.2016 / 19:38

1 answer

2

According to documentation :

  

ENUM values are sorted based on their indexes, which depend on   the order in which the enumeration members were listed in the   column specification. For example, 'no' before 'yes' to   ENUM ('no', 'yes'). Null or empty strings come before all   other enumeration values.

To avoid problems with the ordering of ENUM columns, use:

  • Declare the ENUM list in alphabetical order.
  • Make sure the column is sorted alphabetically and not by index number by encoding ORDER BY CAST (coluna AS CHAR) or ORDER BY CONCAT (coluna) .
  • Try to use:

    ORDER BY CAST(tabela.coluna AS CHAR)

        
    25.02.2016 / 19:52