# To count the number of teachers in each department, including # rows where COUNT(t.name) == 0 SELECT d.name,COUNT(t.name) FROM teacher t RIGHT JOIN dept d ON (t.dept=d.id) GROUP BY d.name;