Jump to content

Archived

This topic is now archived and is closed to further replies.

dfrojd

help query over two tables with count items... please....

Recommended Posts

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

Share this post


Link to post
Share on other sites
[code]
SELECT r.region, COUNT(o.ID)
FROM regions AS r
LEFT JOIN objects AS o ON ( o.region_id = r.region_id )
GROUP BY r.region_id
[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.