Here’s a picture of my database structure:


When I input an Observation, I’m entering a row into Observations but also 0, 1 or more rows into Criteria.
I’m trying to write an SQL statement which allows me to select the Strongest 5 teachers in a specific criteria.
So for example I’d click on Questioning (which might have an ID of 5 in Criteria_Labels), I’d want to return a list of 5 teachers (Teacher_ID from Observations) who have the most rows of Criteria_ID = 5 in Criteria.
The statement that I’ve attempted to write is as follows:
SELECT t.Name AS Teacher_Name
FROM observations o
LEFT JOIN teachers t ON o.Teacher_ID = t.Teacher_ID
LEFT JOIN criteria c ON o.ID = c.Observation_ID
WHERE c.Criteria_ID = 5
ORDER BY COUNT(c.Criteria_ID) DESC
LIMIT 0,5
However, it only appears to return one member of staff. I’m not sure I’ve got this right at all, but hopefully I’m along the right lines.
Can anyone help? Thanks in advance,
1 Answer