Re: Joining more than 2 tables

From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: Jeff Meeks <jmeekssr(at)net-serv(dot)com>
Cc: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Joining more than 2 tables
Date: 2001-04-29 08:14:50
Message-ID: Pine.LNX.4.30.0104291012270.759-100000@peter.localdomain
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)gmx(dot)net http://funkturm.homeip.net/~peter

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Dr. Evil 2001-04-29 09:01:55 Strange PG error
Previous Message Nils Zonneveld 2001-04-29 06:37:44 Re: Joining more than 2 tables