Forum Moderators: open

Message Too Old, No Replies

Select query, order by question

         

Kavkan

4:46 pm on May 23, 2008 (gmt 0)

10+ Year Member



I am trying to pull out some information from the database in user blocks of information, but I can't get it to order properly.

For example, if I have three columns in a table.. one for the date, one for a particular time, and one for the user name.. I am trying to get it to order like this:

Jun. 1/08 ¦ 6:00 ¦ userONE
Jun. 1/08 ¦ 7:00 ¦ userONE
Jun. 1/08 ¦ 8:00 ¦ userONE
Jun. 1/08 ¦ 9:00 ¦ userONE

Jun. 1/08 ¦ 6:00 ¦ userTWO
Jun. 1/08 ¦ 7:00 ¦ userTWO
Jun. 1/08 ¦ 8:00 ¦ userTWO
Jun. 1/08 ¦ 9:00 ¦ userTWO

Jun. 2/08 ¦ 6:00 ¦ userONE
Jun. 2/08 ¦ 7:00 ¦ userONE
Jun. 2/08 ¦ 8:00 ¦ userONE
Jun. 2/08 ¦ 9:00 ¦ userONE

Jun. 2/08 ¦ 6:00 ¦ userTWO
Jun. 2/08 ¦ 7:00 ¦ userTWO
Jun. 2/08 ¦ 8:00 ¦ userTWO
Jun. 2/08 ¦ 9:00 ¦ userTWO

This is the closest I could get the query:
SELECT date, hours, username FROM table1 ORDER BY date, hours, username

However, this orders it like this:

Jun. 1/08 ¦ 6:00 ¦ userONE
Jun. 1/08 ¦ 6:00 ¦ userTWO
Jun. 1/08 ¦ 7:00 ¦ userONE
Jun. 1/08 ¦ 7:00 ¦ userTWO
Jun. 1/08 ¦ 8:00 ¦ userONE
Jun. 1/08 ¦ 8:00 ¦ userTWO
Jun. 1/08 ¦ 9:00 ¦ userONE
Jun. 1/08 ¦ 9:00 ¦ userTWO

Can anyone please give me a hint as to how to write the select query in order to display the data in the way above?

LifeinAsia

5:06 pm on May 23, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



SELECT date, hours, username
FROM table1
ORDER BY date, username, hours

Kavkan

5:29 pm on May 23, 2008 (gmt 0)

10+ Year Member



Wow! :) I guess I've been stareing into the screen for too long.

Thanks LifeinAsia!