Skip to main content
2 of 2
added 51 characters in body

you could do something like this:

SELECT a.neighborhood_name,count(b.event_id) AS event_count
FROM "tblNeighborhoods"  a
LEFT JOIN "tblEvents" b USING (neighborhood_id)
WHERE a.neighborhood_id = x 
GROUP BY a.neighborhood_name

and so on depending on what group you're trying to count

another possibility would be to create additional linkage tables on the containing the ids of the tables containing the categories and the instances you're trying to count. in this case you'd create your linkage table with 2 columns, one to contain each id. then you could select a count from the linkage table like so:

SELECT b.category_name, count(a.instance_id) as instance_count 
FROM "linktable" a
LEFT JOIN "categorytable" b USING(category_id) 
WHERE a.category_id = x
GROUP BY b.category_name