RE: Joining more than 2 tables

From: Jeff Meeks <jmeekssr(at)net-serv(dot)com>
To: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: RE: Joining more than 2 tables
Date: 2001-05-02 14:58:39
Message-ID: 3AF0209F.43DA0C14@net-serv.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

What I am looking for is a query that will return a list of id's with a
sum from table b and a sum from table c like this:

id name sum(b) sum(a)
1 shell 34 50
2 jeff 40 20

Thanks
Jeff Meeks
jmeekssr(at)net-serv(dot)com

P.S. Sorry for sending the reply to you directly Peter I wasn't paying
attention when I hit
the send key

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'.

--

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Raymond Chui 2001-05-02 15:17:51 Re: Thread or not threads?
Previous Message Jeff Eckermann 2001-05-02 14:48:43 RE: Improve a query...