Sort results with month and year

2

I have a table with the mes E ano fields. How can I sort results by month?

I am already ordering by the year

= > SELECT * FROM tabela WHERE id_cliente = '$id_cliente' ORDER BY ano DESC Now how can I order the months too?   Ex (January, feb, mar ...)

PS: mes (varchar 255), year (varchar 255) would this be a bad practice?

    
asked by anonymous 11.07.2017 / 15:44

1 answer

7

In this way with the month of type varchar , you must use FIELD in ORDER BY

SELECT * FROM tabela
WHERE id_cliente = '$id_cliente'
ORDER BY FIELD(mes, 'Janeiro', 'Fevereiro', 'Março', 'Abril', 'Maio', 'Junho', 'Julho', 'Agosto', 'Setembro', 'Outubro', 'Novembro', 'Dezembro'), ano DESC
    
11.07.2017 / 15:51