Received: from localhost (maia-2.hub.org [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id BCEA69FB4E4 for ; Wed, 13 Jun 2007 10:53:27 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-maia, port 10024) with ESMTP id 27728-01 for ; Wed, 13 Jun 2007 10:53:17 -0300 (ADT) X-Greylist: delayed 00:05:20.452162 by SQLgrey-1.7.4 Received: from mail.fbl.cz (mail.fbl.cz [212.80.68.3]) by postgresql.org (Postfix) with ESMTP id 6D2C69FB4E2 for ; Wed, 13 Jun 2007 10:53:23 -0300 (ADT) Received: from localhost (mail.fbl.cz [127.0.0.1]) by mail.fbl.cz (Postfix) with ESMTP id 610108C100; Wed, 13 Jun 2007 15:53:07 +0200 (CEST) Received: from mail.fbl.cz ([127.0.0.1]) by localhost (mail.fbl.cz [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 08719-01; Wed, 13 Jun 2007 15:53:05 +0200 (CEST) Received: from [172.16.18.22] (avojacek.fbl.local [172.16.18.22]) by mail.fbl.cz (Postfix) with ESMTP id A78718C0C8; Wed, 13 Jun 2007 15:53:05 +0200 (CEST) Message-ID: <466FF6B9.1050103@fbl.cz> Date: Wed, 13 Jun 2007 15:52:57 +0200 From: Ales Vojacek Reply-To: alesv@fbl.cz User-Agent: Thunderbird 2.0.0.0 (Windows/20070326) MIME-Version: 1.0 To: "A. R. Van Hook" Cc: pgsql-sql@postgresql.org Subject: Re: join problem References: <466FEEC9.4050300@lake-lotawana.mo.us> In-Reply-To: <466FEEC9.4050300@lake-lotawana.mo.us> X-Enigmail-Version: 0.95.1 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Virus-Scanned: amavisd-new at fbl.cz X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.001 tagged_above=0 required=5 tests=BAYES_50=0.001 X-Spam-Level: X-Archive-Number: 200706/90 X-Sequence-Number: 28580 You can do it like this: select i.ivid, v.eventdate, v.deposit, v.invdate, cai.db, sum(i.tax) as tax, sum(i.tax + i.rowtot) as totalP, (sum(i.tax + i.rowtot) - v.deposit) as balance from invoice v join cai on v.cusid = cai.cusid left outer join invoiceitems i on v.ivid = i.ivid where v.cusid = $cusid group by i.ivid, v.eventdate, v.deposit, v.invdate, cai.db A. Aleš Vojáček FBL Group spol. s r.o. e-mail: alesv@fbl.cz mobil: +420603893335 A. R. Van Hook napsal(a): > I have join problem: > "select i.ivid, v.eventdate, v.deposit, v.invdate, cai.db, > sum(i.tax) as tax, > sum(i.tax + i.rowtot) as totalP, > (sum(i.tax + i.rowtot) - v.deposit) as balance > from invoice v > left outer join > invoiceitems i > on v.ivid = i.ivid > where v.cusid = $cusid > and v.cusid = cai.cusid group by > i.ivid, v.eventdate, v.deposit, v.invdate, cai.db > ERROR: missing FROM-clause entry for table "cai" > > If I add cai to the from clause "from invoice v, cai, I get > ERROR: missing FROM-clause entry for table "cai" > ERROR: invalid reference to FROM-clause entry for table "v" > > Where do I add the cai table reference??? > > thanks >