Re: Joining more than 2 tables - Mailing list pgsql-general

From Peter Eisentraut
Subject Re: Joining more than 2 tables
Date
Msg-id Pine.LNX.4.30.0104291012270.759-100000@peter.localdomain
Whole thread Raw
In response to Joining more than 2 tables  (Jeff Meeks <jmeekssr@net-serv.com>)
List pgsql-general
Jeff Meeks writes:

>     I am trying to join 3 tables
> with this query
>     select a.id, a.name, sum(b.qty), sum(c.qty)
>     from a, b, c
>     where a.id=xxx and b.id=a.id and c.id=a.id
>
> what the sums that get returned look as if they are a cross products of
> the b and c tables.

It's hard to tell what you want to happen, but perhaps you want two
separate queries:

select a.id, a.name, sum(b.qty) from a, b where a.id=xxx and b.id=a.id
group by a.id, a.name;

and the same with 'c' in place of 'b'.

--
Peter Eisentraut   peter_e@gmx.net   http://funkturm.homeip.net/~peter


pgsql-general by date:

Previous
From: will trillich
Date:
Subject: Re: Re: crypt(table.field) ?
Next
From: "Dr. Evil"
Date:
Subject: Strange PG error