Re: JOIN and aggregate problem

From: Tarlika Elisabeth Schmitz <postgresql(at)numerixtechnology(dot)de>
To: Richard Huxton <dev(at)archonet(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: JOIN and aggregate problem
Date: 2009-02-23 15:48:44
Message-ID: 20090223154844.507db25b@dick.coachhouse
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Mon, 23 Feb 2009 15:44:05 +0000
Richard Huxton <dev(at)archonet(dot)com> wrote:

> Tarlika Elisabeth Schmitz wrote:
> > On Fri, 20 Feb 2009 19:06:48 +0000
> > Richard Huxton <dev(at)archonet(dot)com> wrote:
> >> try something like:
> >>
> >> SELECT t1.d, t1.s, t1.c, count(*)
> >> FROM t1
> >> LEFT JOIN (
> >> SELECT d,s,c FROM t2 WHERE x
> >> ) AS t2_true USING (d,s,c)
> >> GROUP BY t1.d, t1.s, t1.c;
> >>
> >> Warning - not tested
> >
> > Many thanks for the quick reply.
> >
> >
> > This suggestion does not work as it returns a count of 1 even when
> > there are no rows in t2 that match (d,s,c) in T1.
>
> Ah, then rather than count(*) you'll want count(t2_true.d) so when you
> get a null because of no match it's not counted. You can use any
> column from t2_true.

Indeed, that works. Now I am spoilt for choice!

--

Best Regards,

Tarlika Elisabeth Schmitz

A: Because it breaks the logical sequence of discussion
Q: Why is top posting bad?

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Emi Lu 2009-02-24 15:27:18 alter column from varchar(32) to varchar(255) without view re-creation
Previous Message Richard Huxton 2009-02-23 15:44:05 Re: JOIN and aggregate problem