elliottbenzle
asked on
Can you use a primary and secondary "order by" in SQL to arrange rows in a recordset?
I'm using ASP/MS access/dreamweaver.
I have a table which contains two fields, one with the date and one with the time. The order is all mixed up. Right now my SQL orders the data according to the date.
"SELECT * FROM hilliardmicroschedule ORDER BY vardate ASC"
But I'm running into the problem that when the dates are the same the times are still all mixed up. Is there a way to alter the SQL so that it orders by vardate first and then orders by vartime. The resulting recordset should be ordered primarily by date and when the dates are the same it will order by time. I'm assuming the code would look something like this:
"SELECT * FROM hilliardmicroschedule ORDER BY vardate ASC (AND ORDER BY vartime ASC)"
You can see the problem on this page under the first schedule (hilliard micro-mini) where the date order is fine but the times are all mixed up.
http://www.glowfishtw.com/flagfootball/schedules.asp?reg=hilliard
Thanks for any help.
I have a table which contains two fields, one with the date and one with the time. The order is all mixed up. Right now my SQL orders the data according to the date.
"SELECT * FROM hilliardmicroschedule ORDER BY vardate ASC"
But I'm running into the problem that when the dates are the same the times are still all mixed up. Is there a way to alter the SQL so that it orders by vardate first and then orders by vartime. The resulting recordset should be ordered primarily by date and when the dates are the same it will order by time. I'm assuming the code would look something like this:
"SELECT * FROM hilliardmicroschedule ORDER BY vardate ASC (AND ORDER BY vartime ASC)"
You can see the problem on this page under the first schedule (hilliard micro-mini) where the date order is fine but the times are all mixed up.
http://www.glowfishtw.com/flagfootball/schedules.asp?reg=hilliard
Thanks for any help.
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
SELECT * FROM hilliardmicroschedule ORDER BY vardate, vartime
or if you wanted the time in reverse within each vardata which was ascending:
SELECT * FROM hilliardmicroschedule ORDER BY vardate, vartime DESC