0

I checked this answer but I have a problem.

SQL Fiddle (I changed INNER JOIN to LEFT JOIN)

What if there is a row in my departments (DDD for example) and no association in the courses table .

As you can see in the fiddle the count for DDD department is 1 like the BUS department has even if there is no data for DDD department. I know that LEFT JOIN does this but how can I modify this ?

How do I get count = 0 for the DDD department?

1 Answer 1

1

Try COUNT(c.section) so when section results null for no association then in count it evaluates to zero

SELECT d.abbreviation
, COUNT(c.section) num
FROM departments d
LEFT JOIN courses c ON c.section LIKE CONCAT(d.abbreviation, "%")
GROUP BY d.abbreviation

Demo

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.