patheticsam Posted January 20, 2009 Share Posted January 20, 2009 Hi! I just have a little question with a SELECT statement. I want to know if it's possible to use AND with the ORDER by command. Let met explain... I have a query here: SELECT date, start_time FROM table1 WHERE id='$id' ORDER BY date if I do that the result will display correctly ascending by date. ex: 01-14-2009(date) 15:00 01-14-2009(date) 12:00 01-15-2008(date) 15:00 01-15-2008(date) 12:00 01-16-2008(date) 15:00 But if I do : SELECT date, start_time FROM table1 WHERE id='$id' ORDER BY date AND start_time The order by dosen't work at all. I want the ORDER BY to order by date in the first time and after by start_time so the result print like this 01-14-2009(date) 12:00 01-14-2009(date) 15:00 01-15-2008(date) 12:00 01-15-2008(date) 15:00 01-16-2008(date) 15:00 Thanks for any help!! Quote Link to comment https://forums.phpfreaks.com/topic/141624-solved-simple-question-with-select-query/ Share on other sites More sharing options...
Philip Posted January 20, 2009 Share Posted January 20, 2009 Don't use AND in the order by, simply use a comma SELECT `date`,` start_time` FROM `table1` WHERE `id`='$id' ORDER BY `date`, `start_time` Quote Link to comment https://forums.phpfreaks.com/topic/141624-solved-simple-question-with-select-query/#findComment-741327 Share on other sites More sharing options...
PFMaBiSmAd Posted January 20, 2009 Share Posted January 20, 2009 Your dates are not being ordered ascending. The month and day of the month are, but the year is not, because you cannot sort a date in that format, which is why the mysql date format is yyyy-mm-dd, Also, you should use a DATETIME data type and store the date and start_time together. Quote Link to comment https://forums.phpfreaks.com/topic/141624-solved-simple-question-with-select-query/#findComment-741330 Share on other sites More sharing options...
patheticsam Posted January 20, 2009 Author Share Posted January 20, 2009 It worked very well! Thank you! Quote Link to comment https://forums.phpfreaks.com/topic/141624-solved-simple-question-with-select-query/#findComment-741337 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.