views:

22

answers:

1

Using SQLite.

   SELECT c.*,
          COUNT(m.course_id) AS "meeting_count",
          COUNT(r.meeting_id) AS "race_count"
     FROM course c
LEFT JOIN meeting m ON m.course_id = c.id
LEFT JOIN race r ON r.meeting_id = m.id
 GROUP BY c.id

Course has meetings has races.

Trying to select the correct count for course meetings and course races. The problem is the above query is returning the same count for "meeting_count" as "race_count". What am I doing wrong?

+1  A: 

try adding DISTINCT like COUNT(DISTINCT m.course_id)

shoebox639
seems to do the trick :) need to expand my data past 1 meeting though, to make sure it calculates that correctly.
esryl