select top 4 in each category (categories complex :( )

Fekla

Registered User.
Local time
Yesterday, 22:11
Joined
Jan 7, 2007
Messages
22
Hi sql wizards,

I am having trouble figuring out the sql syntax. This is the diagram of my database.
attachment.php


What I am trying to do is to select the top 4 points for each UNIT in each EVENT (actually it should be top 2 in each course) and I cant compose it.
i ve arrived at this so far:


SELECT E2R.EventID, E2R.Points, Runners.RunnerID, Runners.Surname, Runners.UnitID
FROM Runners INNER JOIN EventRunner AS E2R ON Runners.RunnerID = E2R.RunnerID
WHERE (((E2R.Points) In (

SELECT TOP 4 EventRunner.EventID, EventRunner.RunnerID, EventRunner.Points, Runners.UnitID
FROM Units INNER JOIN (Runners INNER JOIN EventRunner ON Runners.RunnerID = EventRunner.RunnerID) ON Units.UnitID = Runners.UnitID
WHERE EventRunner =e2r.runnerId AND Runner.unitID=runners.unitID

))
);

Password is 111

Thanks in advance!
 

Attachments

Last edited:
i m so forgetful! its 111
 

Users who are viewing this thread

Back
Top Bottom