Hi,
I have 3 tables
region:
id
region_name
city:
id
city_name
region_id
complaint:
id
date
city_id
I would like to find the counts of complaints by region and I would like
all regions to be displayed, regardless of whether or not complaints
exist for that region. Is left outer join what I'm
On Tue, Jun 16, 2009 at 1:59 PM, Carol
Cheung wrote:
> I would like to find the counts of complaints by region and I would like all
> regions to be displayed, regardless of whether or not complaints exist for
> that region. Is left outer join what I'm looking for?
SELECT R.region_name, Count(*)
Classification: UNCLASSIFIED
Caveats: NONE
Pardon my lameness, I have JUST dipped my toes in PostgreSQL and want to
try this out! I'm probably wrong but here goes my very first PostgreSQL
join attempt!
SELECT region_name, count(complaint.id)
FROM region LEFT JOIN city ON (region.id = city.reg
Richard Broersma wrote:
On Tue, Jun 16, 2009 at 1:59 PM, Carol
Cheung wrote:
I would like to find the counts of complaints by region and I would like all
regions to be displayed, regardless of whether or not complaints exist for
that region. Is left outer join what I'm looking for?
At the risk of being wrong (I'm always ready to learn something
new) - and seemingly I'm only too happy to be wrong!...
And... it might even be that it is exactly the same result - but I
would have proposed;
SELECT
R.region_name,
Count(*) AS RegionComplaints
FROM
Region AS R
Classification: UNCLASSIFIED
Caveats: NONE
Maybe I am way of base here, but I see a reference to region in this
query. However, I think count(cm.id) is correct because some would have
a count of 0. Count(*) would produce counts when there are no
complaints. (If I understand the logic, again, I
On Tue, Jun 16, 2009 at 2:39 PM, Gavin Baumanis wrote:
> At the risk of being wrong (I'm always ready to learn something new) -
> and seemingly I'm only too happy to be wrong!...
>
> And... it might even be that it is exactly the same result - but I would
> have proposed;
>
> SELECT
> R.regi
On Tue, Jun 16, 2009 at 2:40 PM, Rob Sargent wrote:
> Is there a city without a reference to region?
I don't know, but the OP wanted to know complaints by region.
> And wouldn't you want to count(cm.id)?
Count(cm.id) and Count(*) produce the same result. But I like
Count(*) more since it hel
Richard Broersma wrote:
On Tue, Jun 16, 2009 at 2:40 PM, Rob Sargent wrote:
Is there a city without a reference to region?
I don't know, but the OP wanted to know complaints by region.
I didn't try this, but with regionless cities, you may need a full join
if you want a complete
On Tue, Jun 16, 2009 at 2:52 PM, Hall, Crystal M CTR DISA
JITC wrote:
> Maybe I am way of base here, but I see a reference to region in this
> query. However, I think count(cm.id) is correct because some would have
> a count of 0. Count(*) would produce counts when there are no
> complaints. (If
10 matches
Mail list logo