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

From Joel Burton
Subject RE: Joining more than 2 tables
Date
Msg-id Pine.LNX.4.21.0105021341580.17067-100000@olympus.scw.org
Whole thread Raw
In response to RE: Joining more than 2 tables  (Jeff Meeks <jmeekssr@net-serv.com>)
List pgsql-general
On Wed, 2 May 2001, Jeff Meeks wrote:

>     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@net-serv.com

SELECT id, name,
       (SELECT sum(b) FROM b WHERE b.id=a.id) AS sum_b,
       (SELECT sum(c) FROM c WHERE c.id=a.id) AS sum_c
FROM   a;

--
Joel Burton   <jburton@scw.org>
Director of Information Systems, Support Center of Washington


pgsql-general by date:

Previous
From: Doug McNaught
Date:
Subject: Re: Re: Stranger than fiction - EXPLAIN results
Next
From: "Gregory Wood"
Date:
Subject: Re: Stranger than fiction...