F
Fabian
Hi all there,
I have this very complicated query who was good for a local Visual
basic software program, but now that we have moved onto the Internet is
far to slow to be displayed onto an ASP webpage. :-(
It's in an Access 2000 file and It's about the list of the best
athletes - ever - on a certain Competition type in order of score.
The best score is represented by the max score *first* reached for each
athlete.
In other words, if a single athlete reaches the same score in May 2001
and April 2002, then his/her own best score is the May 2001 score.
So, I have an Atheles table, a Competitions and a Scores table.
Fields names should be understandable, I hope.
Now, take a big breath , here it comes:
SELECT A.AthleteName, Score, CompetitionDate, CompetitionPlace, Notes
FROM Competitions AS C INNER JOIN (Athletes AS A INNER JOIN Scores AS
S ON A.AthleteID = S.AthleteID) ON C.CompetitionID = S.CompetitionID
WHERE S.Score = (SELECT MAX(S1.Score) FROM Scores S1 INNER JOIN
Competitions C2 ON C2.CompetitionID=S1.CompetitionID WHERE
S1.AthleteID = A.AthleteID AND CompetitionTypeID=@T) AND
C.CompetitionDate = (SELECT MIN(C1.CompetitionDate) FROM Competitions
C1 INNER JOIN Scores S1 ON S1.CompetitionID = C1.CompetitionID WHERE
S1.AthleteID = A.AthleteID AND S1.Score = S.Score
ORDER BY S.score DESC,competitiondate;
I believe that if I manage to replace the "WHERE S.Score=(SELECT...)"
with a further "INNER JOIN ([SELECT...]) the execution should be
quicker, but my brain does not work today and I cannot manage to
get it into work properly...
Could any of you help, pleeeese ?
Thanks
Fab.
I have this very complicated query who was good for a local Visual
basic software program, but now that we have moved onto the Internet is
far to slow to be displayed onto an ASP webpage. :-(
It's in an Access 2000 file and It's about the list of the best
athletes - ever - on a certain Competition type in order of score.
The best score is represented by the max score *first* reached for each
athlete.
In other words, if a single athlete reaches the same score in May 2001
and April 2002, then his/her own best score is the May 2001 score.
So, I have an Atheles table, a Competitions and a Scores table.
Fields names should be understandable, I hope.
Now, take a big breath , here it comes:
SELECT A.AthleteName, Score, CompetitionDate, CompetitionPlace, Notes
FROM Competitions AS C INNER JOIN (Athletes AS A INNER JOIN Scores AS
S ON A.AthleteID = S.AthleteID) ON C.CompetitionID = S.CompetitionID
WHERE S.Score = (SELECT MAX(S1.Score) FROM Scores S1 INNER JOIN
Competitions C2 ON C2.CompetitionID=S1.CompetitionID WHERE
S1.AthleteID = A.AthleteID AND CompetitionTypeID=@T) AND
C.CompetitionDate = (SELECT MIN(C1.CompetitionDate) FROM Competitions
C1 INNER JOIN Scores S1 ON S1.CompetitionID = C1.CompetitionID WHERE
S1.AthleteID = A.AthleteID AND S1.Score = S.Score
ORDER BY S.score DESC,competitiondate;
I believe that if I manage to replace the "WHERE S.Score=(SELECT...)"
with a further "INNER JOIN ([SELECT...]) the execution should be
quicker, but my brain does not work today and I cannot manage to
get it into work properly...
Could any of you help, pleeeese ?
Thanks
Fab.