mysqlsqlsql-order-bydayofweek

Order by day_of_week in MySQL


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

Note that MONDAY should goes first, not SUNDAY.


Solution

  • 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');