T
Todd Martin
OK, I'm having some trouble updating the values of a column in
one table to the maximum value of a column in a different table.
Here's the relevant table design:
tblStudentInfo
nStudentNum
nStudentLevel
tblTestCandidates
nStudentId
nTestLevel
nResult
nTestEvent
What I'm trying to do is set tblStudentInfo.nStudentLevel for each
student equal to the maximum nTestLevel in tblTestResults where
nTestEvent matches a provided value and nResult is equal to 1.
For a given test event, a student may take multiple tests, but cannot
pass level (n+1) if level n has not been passed.
I can find the maximum value for ALL students with the query
SELECT Max(tblTestCandidates.nTestLevel) AS MaxLevel
FROM tblStudentInfo, tblTestCandidates
WHERE ((tblStudentInfo.nStudentNum=tblTestCandidates.nStudentId) AND
(nTestEvent=4) AND (nResult=1));
but I need to be able to get the max for each student and then set
that value as tblStudentInfo.nStudentLevel.
Any suggestions, as well as a suggestion for a good book on writing
SQL queries, would be appreciated.
Thanks,
--tdm
one table to the maximum value of a column in a different table.
Here's the relevant table design:
tblStudentInfo
nStudentNum
nStudentLevel
tblTestCandidates
nStudentId
nTestLevel
nResult
nTestEvent
What I'm trying to do is set tblStudentInfo.nStudentLevel for each
student equal to the maximum nTestLevel in tblTestResults where
nTestEvent matches a provided value and nResult is equal to 1.
For a given test event, a student may take multiple tests, but cannot
pass level (n+1) if level n has not been passed.
I can find the maximum value for ALL students with the query
SELECT Max(tblTestCandidates.nTestLevel) AS MaxLevel
FROM tblStudentInfo, tblTestCandidates
WHERE ((tblStudentInfo.nStudentNum=tblTestCandidates.nStudentId) AND
(nTestEvent=4) AND (nResult=1));
but I need to be able to get the max for each student and then set
that value as tblStudentInfo.nStudentLevel.
Any suggestions, as well as a suggestion for a good book on writing
SQL queries, would be appreciated.
Thanks,
--tdm