November 17 2014

Order by day of the week from Monday to Sunday

Tagged Under :

MySQL
A lot of people may be will ask how to sort day of the week with SQL query. Because Monday to Sunday it was string and MySQL cannot differentiate it was day or string inside the table.

But you are allow define inside the query how order the query with ORDER BY FIELD().

ORDER BY FIELD([fieldname], 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday');

ORDER BY FIELD actually is custom ORDER BY in MySQL. It easy to let you sort the results needed by you.

Make a Comment

You must be logged in to post a comment.