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 Quote Link to comment 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] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.