Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.