Re: extend "group by" to include "empty relations" ?

From: Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>
To: peter pilsl <pilsl(at)goldfisch(dot)at>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: extend "group by" to include "empty relations" ?
Date: 2007-12-13 19:10:17
Message-ID: 20071213191017.GM6262@alvh.no-ip.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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)

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Gregory Stark 2007-12-13 19:12:04 Re: Hash join in 8.3
Previous Message Uwe C. Schroeder 2007-12-13 19:05:35 Re: For the SQL gurus out there