It may be a little difficult to explain, but I will try.
I want to display a list of categories (stored in 1 table) and the number of domains associated with each category (stored in another table).
In this case, the monkey’s key is that each domain has a set of records associated with it (which are stored in the third table). I want to show only those categories that have domains associated with them, and the number of domains should reflect only domains that have records associated with them (from the third table).
My current request
SELECT r.rev_id, c.cat_id, c.cat_name, count(d.dom_id) As rev_id_count FROM reviews r
INNER JOIN domains d ON r.rev_domain_from=d.dom_id
INNER JOIN categories c ON d.dom_catid=c.cat_id
WHERE rev_status = 1
GROUP BY cat_name
ORDER BY cat_name
The correct category names are selected here, but a false value is displayed (rev_id_count). If there are 2 domains in a category and there are 2 entries in each domain, it will display a counter of 4, if it should be 2.
user15063