kaulainais
kaulainais

Reputation: 125

MySQL Order by month in specific order

I have a list of month in database. In query output I would like to Order by month But in very specific order. ('DEC', 'JUL', 'MAR', 'OCT,' 'MAY', 'JUN', 'FEB', 'AUG', 'SEP', 'APR', 'NOV', 'JAN') Something like:

Select month from month_table
Order by month

How to specify customized Order?

Upvotes: 0

Views: 158

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1271161

In MySQL, you can use the field() function:

order by field(month, 'DEC', 'JUL', 'MAR', 'OCT,' 'MAY', 'JUN', 'FEB', 'AUG', 'SEP', 'APR', 'NOV', 'JAN')

Upvotes: 1

Related Questions