Here is the code I used before. I did not get what I wanted. Your help is
much appreciated. Field "Term" is text not number.
A scenario could be like this: a student could be admitted more than once in
the same program (withdrew then back) and transferred among different campus.
To determine if a student is promoted to a higher level is to check the
enrollment to a required class (Class). The earliest Term a student took
either HIST316 or DRAM300 is a level 3 student. The query should keep the
first Enrollment Date; the first enrolled CampusName, the first Term this
person is promoted to level 3 (the term a student took the required course),
and the course number.
ID CampusName EnrollDate Subject Level Term Class Mark
1 A Sep-96 HIST 3 199909 316 48
1 B Sep-96 HIST 3 200009 316 61
2 B Sep-97 HIST 3 199809 316 56
2 B Sep-99 HIST 3 200109 316 68
3 C Sep-96 HIST 3 199809 316 W
3 C Sep-99 HIST 3 199909 316 58
4 A Sep-96 HIST 3 199809 316 W
4 C Sep-96 HIST 3 200009 316 58
4 C Sep-96 DRAM 3 200209 300 58
5 D Sep-96 DRAM 3 200409 300 63
5 D Sep-00 DRAM 3 200409 300 63
What I wanted is as follows:
ID CampusName EnrollDate Subject Level Term Class Mark
1 A Sep-96 HIST 3 199909 316 48
2 B Sep-97 HIST 3 199809 316 56
3 C Sep-96 HIST 3 199809 316 W
4 A Sep-96 HIST 3 199809 316 W
5 D Sep-96 DRAM 3 200409 300 63
SELECT DISTINCT tblStudent.StudntID, tblAdmission.CampusName,
Min(tblAdmissionion.EnrollDate) AS MinOfEnrollDate, tblStudent.Level,
tblStudentCourse.Term, tblStudentCourse.CoursNum, tblStudentCourse.Grade
FROM ((tblStudent INNER JOIN tblStudentCourse ON tblStudent.StudntID =
tblStudentCourse.StudntID) INNER JOIN tblAdmission ON tblStudent.StudntID =
tblAdmission.StudntID) INNER JOIN tblStudentName ON tblStudent.StudntID =
tblStudentName.StudntID
WHERE (((tblStudentCourse.Subject)="HIST" Or
(tblStudentCourse.Subject)="DRAM") AND ((tblStudentCourse.CoursNum)="316"))
Or (tblStudentCourse.CoursNum)="300"))
ORDER BY Min(tblAdmission.AdmDate)
Marshall Barton said:
A subquery (instead of a separate query) might work, but the
critical point is being able to use a unique sort order to
determine "first" and "last".
I'd be happy to suggest something but you have to explain
how to use what fields to create the unique sorting.
--
Marsh
MVP [MS Access]
Thank you for telling me that the records in a table are not ordered. Should
I try subquery?