Reputation: 633
I have an Access
database which contains a Grads
table :
Grads
- studentId
- courseId
- tryNumber
- semesterId
- finalGrad
How to get all info (studentName, courseName, courseId, finalGrade
) from lines with max tryNumber
(last try ) ?
Upvotes: 2
Views: 142
Reputation: 247630
If you only want the one row with the max
trynumber, then you should be able to use:
select g.studentid,
g.courseid,
g.trynumber,
g.semesterid,
g.finalgrade
from grads g
inner join
(
select max(tryNumber) MaxTry
from grads
) m
on g.trynumber = m.maxtry
If you want to return each student with the max(tryNumber)
, then you can use:
select g.studentid,
g.courseid,
g.trynumber,
g.semesterid,
g.finalgrad
from grads g
inner join
(
select studentid, max(tryNumber) MaxTry
from grads
group by studentid
) m
on g.trynumber = m.maxtry
and g.studentid = m.studentid
Upvotes: 4
Reputation: 2530
You can use:
Select studentName, courseName, courseId, finalGrade From Grads
Where tryNumber=(Select MAX(tryNumber) From Grads)
Upvotes: 0
Reputation: 4892
This should work for you:
SELECT studentName,
courseName, couseId,
finalGrade, MAX(tryNumber)
FROM grads
GROUP BY studentName, courseName, couseId, finalGrade
Upvotes: 0