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 ? Quote 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 Quote 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. Quote 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? Quote 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) Quote 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? Quote Link to comment https://forums.phpfreaks.com/topic/162555-order-by-two-fields/#findComment-860964 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.