Avatar of elliottbenzle
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.
ASPSQL

Avatar of undefined
Last Comment
kmslogic
ASKER CERTIFIED SOLUTION
Avatar of Haris Dulic
Haris Dulic
Flag of Austria image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of kmslogic
kmslogic
Flag of United States of America image

Samo's got it, you can put multiple sub orderings separated by commas after ORDER BY and of course ignore the double quotes and ending parenthesis...  You also don't need to specify ascending as this is the default but can put DESC after each item in the list.

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

Active Server Pages (ASP) is Microsoft’s first server-side engine for dynamic web pages. ASP’s support of the Component Object Model (COM) enables it to access and use compiled libraries such as DLLs. It has been superseded by ASP.NET, but will be supported by Internet Information Services (IIS) through at least 2022.

82K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo