dfrojd Posted September 11, 2006 Share Posted September 11, 2006 Hi,I have two tables (mysql).One: "regions" with the fields "region_id" and "region"Two: "objects" with the fields "ID"; "region_id" and "properties".Every object belongs to a specific region (linked by region_id).Now I want a list of all my regions sorted by, and displaying, how many objects belong to every specific region.Can anyone help me with this one?Thanks Dennis Link to comment https://forums.phpfreaks.com/topic/20366-help-query-over-two-tables-with-count-items-please/ Share on other sites More sharing options...
fenway Posted September 11, 2006 Share Posted September 11, 2006 [code]SELECT r.region, COUNT(o.ID)FROM regions AS rLEFT JOIN objects AS o ON ( o.region_id = r.region_id )GROUP BY r.region_id[/code] Link to comment https://forums.phpfreaks.com/topic/20366-help-query-over-two-tables-with-count-items-please/#findComment-89794 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.