timcclayton Posted July 16, 2006 Share Posted July 16, 2006 Hello all.I am using a SELECT query to drag out records sorted by WEEKDAY. The trouble is, they sort themselves alphabetically (naturally) and this looks a bit stupid when Friday is the "first" day. Is there a way to sort by actual weekday order?Code I am using is:[code]"SELECT * FROM FLIGHTS ORDER BY 'intdom', 'day' ASC"[/code]where "day" is the weekday field. Quote Link to comment https://forums.phpfreaks.com/topic/14780-how-to-order-by-weekday-but-not-alphabetically/ Share on other sites More sharing options...
Barand Posted July 16, 2006 Share Posted July 16, 2006 [code]"SELECT * FROM FLIGHTS ORDER BY intdom, CASE WHEN day='Sunday' THEN 0 WHEN day='Monday' THEN 1 WHEN day='Tuesday' THEN 2 WHEN day='Wednesday' THEN 3 WHEN day='Thursday' THEN 4 WHEN day='Friday' THEN 5 WHEN day='Saturday' THEN 6 END"[/code] Quote Link to comment https://forums.phpfreaks.com/topic/14780-how-to-order-by-weekday-but-not-alphabetically/#findComment-59034 Share on other sites More sharing options...
effigy Posted July 16, 2006 Share Posted July 16, 2006 or [tt]date_format(day, '%w')[/tt] Quote Link to comment https://forums.phpfreaks.com/topic/14780-how-to-order-by-weekday-but-not-alphabetically/#findComment-59036 Share on other sites More sharing options...
Barand Posted July 16, 2006 Share Posted July 16, 2006 I got the impression that 'day' column contained the day name and was not a DATE column Quote Link to comment https://forums.phpfreaks.com/topic/14780-how-to-order-by-weekday-but-not-alphabetically/#findComment-59038 Share on other sites More sharing options...
effigy Posted July 16, 2006 Share Posted July 16, 2006 Good point. I'll go wake up... :) Quote Link to comment https://forums.phpfreaks.com/topic/14780-how-to-order-by-weekday-but-not-alphabetically/#findComment-59040 Share on other sites More sharing options...
timcclayton Posted July 16, 2006 Author Share Posted July 16, 2006 Yes that's correct, the first example worked beautifully. Thanks very much Barand (and effigy too for trying to help) - much appreciated! Quote Link to comment https://forums.phpfreaks.com/topic/14780-how-to-order-by-weekday-but-not-alphabetically/#findComment-59041 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.