Question : Nested Subquery efficiency

Harfang showed me the light with subqueries, then I quickly drowned myself with them using nested subqueries.
Basically these 2 queries sum up the points per event teamAbbrev rank them, then assign points based on that rank.

The problem is, the 2nd query I have listed, which is used in the first query takes about 5seconds to run. The 1st query takes somewhere around 10minutes. And currently I have 1/5 of the data that there will be.

How can I make this faster? I have indexed every field that was relevant, and all field data types are the best they can be.
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
qryTeamPtsScaled:
 
SELECT Q1.D1, Q1.TeamAbbrev, Q1.EventAbbrev, tblPts.Pts AS Scale, Q1.Championship
FROM qryTeamPtsSub AS Q1, tblPts
WHERE (((
  SELECT COUNT(*) FROM qryTeamPtsSub AS Q2 
  WHERE Q2.Raw >= [Q1].[raw] AND Q2.D1 =  Q1.D1 AND  Q1.EventID = Q2.EventID)=[tblPts].[position]) AND tblPts.ScoreID=3)
ORDER BY Q1.D1, Q1.TeamAbbrev, Q1.EventAbbrev;
 
qryTeamPtsSub:
SELECT tblTeam.D1, tblTeam.TeamAbbrev, Sum(qryTeamRaw.Pts) AS Raw, tblEvent.EventAbbrev, tblEvent.EventID, tblEvent.Championship
FROM tblTeam INNER JOIN 
  (tblEvent INNER JOIN 
    (tblRace INNER JOIN 
      (tblRider INNER JOIN qryTeamRaw ON tblRider.RiderID = qryTeamRaw.RiderID)
       ON tblRace.RaceID = qryTeamRaw.RaceID)
    ON tblEvent.EventID = tblRace.EventID) 
  ON tblTeam.TeamAbbrev = tblRider.TeamAbbrev
GROUP BY tblTeam.D1, tblTeam.TeamAbbrev, tblEvent.EventAbbrev, tblEvent.EventID, tblEvent.Championship;

Answer : Nested Subquery efficiency

I thought count(*) was optimized to be faster than a count on a field. There will be a lot of nulls, like 75% are going to be null, and won't be found in tblPts

I changed the * to one of the fields in the query that doesn't have nulls, but it was still more than a 1min to query, then I canceled it.

I'm going to try making the subquery a MakeTable, and querying that.
Random Solutions  
 
programming4us programming4us