This works
SELECT DISTINCT b.b_id
FROM b INNER JOIN c
ON b.b_id=c.b_id
WHERE c.active='yes' AND b.featured='no'
When the results should be 0 rows returned, this returns a null row with count = 0
SELECT DISTINCT b.b_id, COUNT(c.c_id) AS count
FROM b INNER JOIN c
ON b.b_id=c.b_id
WHERE c.active='yes' AND b.featured='no'
Am I doing something wrong?
I think you want a
left joininstead of aninner joinsince you want to return a count of 0 instead of a missing row when there is no matchingcrecord for a givenbrecord.Also, you should include a
group bywhen using an aggregate function, such ascount.