starphp Posted June 17, 2009 Share Posted June 17, 2009 I wish to select records order by two fields in the descending format: table: details id month year 1 -----01 ------ 2009 2 -----05 ------ 2008 3 -----05 ------ 2009 need a recent records ie 05 - 2009 then 01 - 2009 then 05 -- 2008 Is that possible with SQL Query ? Link to comment https://forums.phpfreaks.com/topic/162555-order-by-two-fields/ Share on other sites More sharing options...
trq Posted June 17, 2009 Share Posted June 17, 2009 SELECT * FROM tbl ORDER BY year,month DESC Link to comment https://forums.phpfreaks.com/topic/162555-order-by-two-fields/#findComment-857926 Share on other sites More sharing options...
starphp Posted June 17, 2009 Author Share Posted June 17, 2009 It displays the Month in the descending order but not the Year. Link to comment https://forums.phpfreaks.com/topic/162555-order-by-two-fields/#findComment-857957 Share on other sites More sharing options...
trq Posted June 17, 2009 Share Posted June 17, 2009 What data types are you using? Link to comment https://forums.phpfreaks.com/topic/162555-order-by-two-fields/#findComment-857959 Share on other sites More sharing options...
starphp Posted June 17, 2009 Author Share Posted June 17, 2009 For the filed, MONTH used "char (2)" For the Year filed used "Year (4) Link to comment https://forums.phpfreaks.com/topic/162555-order-by-two-fields/#findComment-857966 Share on other sites More sharing options...
fenway Posted June 22, 2009 Share Posted June 22, 2009 Yikes... why not use a proper DATE field? Link to comment https://forums.phpfreaks.com/topic/162555-order-by-two-fields/#findComment-860964 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.