Re: extend "group by" to include "empty relations" ? - Mailing list pgsql-general

From Alvaro Herrera
Subject Re: extend "group by" to include "empty relations" ?
Date
Msg-id 20071213191017.GM6262@alvh.no-ip.org
Whole thread Raw
In response to extend "group by" to include "empty relations" ?  (peter pilsl <pilsl@goldfisch.at>)
List pgsql-general
peter pilsl wrote:

> But there is a problem now: There are also entries in fn_kat which dont
> have corresponding entries in fn_dokumente and this entries should be
> listed too. With the proper count=0 !!

Your problem is not on the GROUP BY, but rather that you need an outer
join.  Try something like

 select k.kategorie,count(d.oid) from fn_kat k left join fn_dokumente d
 on k.id=d.kategorie group by k.kategorie;

--
Alvaro Herrera                               http://www.PlanetPostgreSQL.org/
"The first of April is the day we remember what we are
the other 364 days of the year"  (Mark Twain)

pgsql-general by date:

Previous
From: "Uwe C. Schroeder"
Date:
Subject: Re: For the SQL gurus out there
Next
From: "Joshua D. Drake"
Date:
Subject: Re: Slow PITR restore