I have a query where I select animals at a particular level along with some information about their species…
SELECT animals.id, animals.name, species.name, species.exlevel
FROM `animals`
INNER JOIN species ON animals.spid = species.id
WHERE animal.level=1
I am trying to append this query to include a count of all comments from the comments table left for each animal. However, I can’t find the optimal way to do it. The following obviously doesn’t work but is what I am looking to do… without doing two separate queries.
SELECT animals.id, animals.name, species.name, species.exlevel, COUNT(comments.id)
FROM `animals`
INNER JOIN species ON animals.spid = species.id
INNER JOIN comments ON animals.id = comments.anid
WHERE animal.level =1
AND comments.type =2
1 Answer