Received: from localhost (maia-1.hub.org [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id B89059FB418 for ; Thu, 26 Jul 2007 23:18:53 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.191]) (amavisd-maia, port 10024) with ESMTP id 44826-01 for ; Thu, 26 Jul 2007 23:18:51 -0300 (ADT) X-Greylist: whitelisted by SQLgrey-1.7.5 Received: from mail01.syd.optusnet.com.au (mail01.syd.optusnet.com.au [211.29.132.182]) by postgresql.org (Postfix) with ESMTP id 6C0B39FB40D for ; Thu, 26 Jul 2007 23:18:50 -0300 (ADT) Received: from [127.0.0.1] (online4-new.lnk.telstra.net [139.130.169.227]) (authenticated sender plengada@optusnet.com.au) by mail01.syd.optusnet.com.au (8.13.1/8.13.1) with ESMTP id l6R2IiZe014757 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Fri, 27 Jul 2007 12:18:47 +1000 Message-ID: <46A955FC.8000105@autoledgers.com.au> Date: Fri, 27 Jul 2007 10:18:36 +0800 From: Paul Lambert User-Agent: Thunderbird 2.0.0.5 (Windows/20070716) MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: Re: Join question References: <00a001c7cff0$300ff000$9b0014ac@wbaus090> In-Reply-To: <00a001c7cff0$300ff000$9b0014ac@wbaus090> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200707/162 X-Sequence-Number: 28897 Phillip Smith wrote: > Whoops, I forgot the JOIN conditions! Fixed below > > -----Original Message----- > From: Phillip Smith [mailto:phillip.smith@weatherbeeta.com.au] > Sent: Friday, 27 July 2007 11:47 > To: 'pgsql-sql@postgresql.org' > Subject: RE: [SQL] Join question > > > This might give you a starting point if I understand you correctly... > > SELECT h.invoice_number, > h.customer, > l.item, > l.amount > FROM lines AS l > JOIN headers AS h ON l.invoice_number = h.invoice_number > UNION > SELECT h.invoice_number, > h.customer, > s.item, > s.amount > FROM sundries AS s > JOIN headers AS h ON s.invoice_number = h.invoice_number > ORDER BY invoice_number, item > Forgot all about union - I had two individual views, one for invoice+parts, one for invoice+sundries... didn't think of union to combine the two views together. Perfect solution, you've done it for me again Phillip, thanks. -- Paul Lambert Database Administrator AutoLedgers