Please note that I have seen a similar query here, but think my query is different enough to merit a separate question.
Suppose that there is a database with the fol
You could do it more simply:
select c.id, c.cname, count(distinct o.pid) as `uniques` from o join c on c.id = o.cid group by c.id having `uniques` > 10