I’m trying to create an SQL statement that joins two tables and returns a count. I need all the records returning even if there are no items found for the count.
If I just do this:
SELECT s.subject,s2.subject from subjects s
left join subjects s2 on s.parent_id = s2.id
It’s fine but there’s no count. I tried joining it to the other table I need to do the count on by doing this:
SELECT s.subject,s2.subject,count(q.id) from subjects s
left join subjects s2 on s.parent_id = s2.id
join questions q on q.subject_id = s.id
but I just get one result that doesn’t have any meaning at all.
Try this: