Order by day_of_week in MySQL

Bogdan Gusiev picture Bogdan Gusiev · Jul 14, 2009 · Viewed 21.8k times · Source

How can I order the mysql result by varchar column that contains day of week name?

Note that MONDAY should goes first, not SUNDAY.

Answer

Glen Solsberry picture Glen Solsberry · Jul 14, 2009

Either redesign the column as suggested by Williham Totland, or do some string parsing to get a date representation.

If the column only contains the day of week, then you could do this:

ORDER BY FIELD(<fieldname>, 'MONDAY', 'TUESDAY', 'WEDNESDAY', 'THURSDAY', 'FRIDAY', 'SATURDAY', 'SUNDAY');