MySQL Forums
Forum List  »  Newbie

Help with Join Query
Posted by: Rob James
Date: February 12, 2010 06:59PM

This is a typical Query I'm using:

SELECT
AgeRangeNames.ID
, COUNT(Students.AgeRange) AS Total
FROM
AgeRangeNames
LEFT JOIN Students
ON AgeRangeNames.ID = Students.AgeRange
LEFT JOIN Registrations
ON Registrations.StudentID = Students.ID
WHERE Registrations.Year = "10"
AND Registrations.Status = "1"
AND Registrations.ClassID ="58"
GROUP BY
AgeRangeNames.ID

The results I get are:

F1 1
F2 1
F3 1
F5 1
M1 1
M3 2
M5 1

Which are correct, but I also want the missing AgeRangeName.ID, i.e.

F1 1
F2 1
F3 1
F4 0
F5 1
M1 1
M2 0
M3 2
M4 0
M5 0

Once I apply the WHERE conditions, I'm not sure how to get those missing values.

Help?

Options: ReplyQuote


Subject
Written By
Posted
Help with Join Query
February 12, 2010 06:59PM
February 13, 2010 03:25AM
February 13, 2010 07:54AM
February 14, 2010 10:02PM
February 15, 2010 04:49AM
February 15, 2010 11:58AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.