Jump to content

[SOLVED] Simple question with SELECT query!


patheticsam

Recommended Posts

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!!

 

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.