Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Top 3 best times for each distance

Status
Not open for further replies.

VRunner

IS-IT--Management
Joined
Jun 25, 2009
Messages
2
Location
GB
Hi all

I've tried to follow the MS example in which works for just 2 tables, but I have more!

tblDistances / tblRaces / tblResults.
Each race has a single distance.
Each distance can apply to many races.
each race has many results.

So the objective is to find the top 3 results for each distance, and show the race name as a consequence. My query so far is as below which just returns the overall top 3 and not per group.

As always - help & guidance is appreciated.

SELECT tblRaces.RaceName, tblRaces.DistID, tblresults.ResTime, tblresults.ResName
FROM tblDistance INNER JOIN (tblRaces INNER JOIN tblresults ON tblRaces.RaceID = tblresults.RaceID) ON tblDistance.DistID = tblRaces.DistID
WHERE (((tblresults.ResTime) In (Select Top 3 [ResTime] From tblResults Where [tblRaces.DistID]=[tblDistance].[DistID] Order By [ResTime] Asc)))
ORDER BY tblRaces.DistID, tblresults.ResTime;
 
Change this:
Where [tblRaces.DistID]=[tblDistance].[DistID]
to this:
Where RaceID=tblRaces.RaceID

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
If you're returning the wrong values, it's b/c you're looking for the wrong values in your SELECT Clause.

SELECT tblRaces.RaceName, tblRaces.DistID, tblresults.ResTime, tblresults.ResName

You said it's returning the races/times, and not the distances/times... so you need to adjust your SELECT Clause..

So, perhaps change that to this:

SELECT tblRaces.[highlight]Distance[/highlight], tblRaces.DistID, tblresults.ResTime, tblresults.ResName

Or else, please better explain what you're trying to do..

Perhaps, are you wanting to return the actual distance from a different table, instead of just the distanceID? If so, just substitute the correct table/field combination.

--

"If to err is human, then I must be some kind of human!" -Me
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top