Ok, the root of this problem is actually in your database design, not your select statement. In order to do what your wanting you have three options:
1) Redesign your db (I'll hit this later) which will get you closer, but not exactly what you want.
2) Use Independant select statements for dept (ACCT), course number(251), class number (03/04/05)
3) Write one select statement, but keep track of current dept and course while your looping through:
Code:
Dim tDept, tCourse
Do Until rs.EOF
If rs("department") <> tDept Then
Response.Write "Department: " & rs("department") & "<br>"
tDept = rs("department")
End If
If rs("course") <> tCourse Then
Response.Write "<div style='padding-left:1em;'>" & rs("course") & "</div>"
tCourse = rs("course")
End If
Response.Write "<div style='padding-left:2em;'>" & rs("class") & "</div>"
rs.MoveNext
Loop
That should give you something like:
ACCT
101
01
03
05
251
03
04
05
BIO
151
01
02
03
Ok, so back to the db design. It appears your designing a school scheduler. In terms of school a department is pretty obvious, but a course and class are very differant.
A course has a department and numerical assignment, as well as a description. It does not have a teacher or a meeting time or a building. You can think of it as the base definition for classes to use.
A class is an instantiation of a course. If we have 5 classes for BIO 101 then they will all hae the same department, the same course number, the same description, etc But in this case they will also have a building, a meeting room, a teacher, a semester, and a meeting time (among many other possibilities, like seating, etc)
So here is an example set of records:
Code:
dept | crse | class | title | description | teacher | time
-----+------+-------+-------+-------------+---------+------
ACCT | 251 | 03 | Acco..| Intermedia..| Phillips| 1:30
ACCT | 251 | 04 | Acco..| Intermedia..| Brown | 12:00
ACCT | 251 | 05 | Acco..| Intermedia..| Smith | 9:00
I left off some important fields for space conservation.
Can you see what is happening? We are repeating several fields over and over. This is bad. What happens now is if you need to update the course description your actually updating it in multiple locations, this causes a hit on performance as well as opening the door for errors (descriptions not matching for two classes in same course, etc)
So what we want to do is move the redundant fields to their own table. Lets call it Course
So here are our two tables now:
Course:
dept
crse
title
description
Class:
class_number
teacher
time
We need some primary keys. Text keys are generally considered bad, so lets go with auto incrememnting integer id's (autonumber fields in access, seeded integers in most other db's)
Course:
course_id
dept
crse
title
description
Class:
class_id
course_id
class_number
teacher
time
Notice I added the course_id to class as well to define a relationship between course and class. In this case we want a one-to-many relationship. In other words for each course there can be 0 or more classes that belong to it.
Now lets put our above three records in our new tables:
Code:
Course Table:
course_id | dept | crse | title | description
----------+------+------+-------+------------------------
1 | ACCT | 251 | Acco..| Intermediate accounting for...
Class Table:
class_id | course_id | class_number | teacher | time
---------+-----------+--------------+---------+--------
1 | 1 | 03 | phillips| 1:30
2 | 1 | 04 | brown | 12:00
3 | 1 | 05 | smith | 9:00
Now when we want just the courses we can select fro just the courses table, if you want just the classes than instead of getting all of the extra course info you can select directly from the class table. You still can't select all the dept, course, and class info in one select statement without getting duplicate dept's and courses, but thats because you'll never be able to do that unless there is only one class per course and one course per dept.
But we have cut down on the data duplication, communications duplication, and time wasted by the server sending you fields you don't need.
Example SQL:
"SELECT * FROM Course" 'just the course info
"SELECT * FROM Class" 'all the class info without course descs, etc
"SELECT * FROM Class WHERE course_id = " & Request.Form("course_id"

'form form on a previous page, dropdown select?
"SELECT * FROM Course, Class WHERE Course,course_id = Class.class_id" 'all the info you would get now if you did a Select * on your current db layout
Don't know if this will help or not, got kind of carried away.
-Tarwn Experts are only people who have realized how much they will never know about a language.
________________________________________________________________________________
Want to get great answers to your Tek-Tips questions? Have a look at faq333-2924