Dlayman
04-30-2002, 05:49 PM
I have a table that contains a student ID field and 10 Procedure fields (Procedure1..Procedure10). The students select procedures from a drop down menu on our website to populate their procedure fields for one record.
Example Student 1
Procedure1: item1
Procedure2: item2
Procedure3: item3
Example Student 2
Procedure1: item6
Procedure2: item3
Procedure3: item1
I need a query that can count how many times an item appears in all 10 procedure fields combined for a particular student id.
I hope this makes some since because I have fried my brain trying to figure it out.
David R
05-01-2002, 07:14 AM
The reason you're frying your brain over this is you should not have 10 fields. What if your school later decides to allow 12 procedures, or only 8? You'll have to go back and rework your tables, code, reports, etc.
A relational database recognizes 0, 1, or Many of something. "10" is a meaningless number to it, it's just part of "many". To properly organize your data you need three tables:
tableStudents: StudentID (PK), all other student-specific information.
tableProcedures: tableProcedures should be a reference table of the acceptable options. It should contain only fields relating to defining a procedure, but have all of the information about that procedure. ProcedureID (Primary Key - can be Autonumber probably unless you already have an identifier), ProcName, ProcLength, ProcClassification, ProcStatus, etc.
This table becomes the basis of your drop-down list.
Now a third table (we'll call it tableStudentProcedures) needs only two fields to connect the two: StudentID and ProcedureID. They should make up a multi-part Primary Key for this table, and in Tools>Relationships you should define a one-to-many relationship in either direction to the other two tables.
Now one student can have many procedures, and one procedure can have many students. This is a many-to-many relationship, and now your data is actually usable.
To count how many procedures each student has, run a Select Query on tableStudentProcedures, turn on Totals (the Sigma button) Group By StudentID, Count ProcedureID, run the query.
Voila!