Received: from localhost (maia-4.hub.org [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id 136C29FB3B7 for ; Thu, 26 Jul 2007 22:33:38 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 82814-06 for ; Thu, 26 Jul 2007 22:33:35 -0300 (ADT) X-Greylist: whitelisted by SQLgrey-1.7.5 Received: from mail02.syd.optusnet.com.au (mail02.syd.optusnet.com.au [211.29.132.183]) by postgresql.org (Postfix) with ESMTP id C31939FB3B3 for ; Thu, 26 Jul 2007 22:33:34 -0300 (ADT) Received: from [127.0.0.1] (online4-new.lnk.telstra.net [139.130.169.227]) (authenticated sender plengada@optusnet.com.au) by mail02.syd.optusnet.com.au (8.13.1/8.13.1) with ESMTP id l6R1XSOk018756 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Fri, 27 Jul 2007 11:33:31 +1000 Message-ID: <46A94B60.4030901@autoledgers.com.au> Date: Fri, 27 Jul 2007 09:33:20 +0800 From: Paul Lambert User-Agent: Thunderbird 2.0.0.5 (Windows/20070716) MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: Join question 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/158 X-Sequence-Number: 28893 I have a database in a parts sales environment that I am having a little difficulty with a join query - trying to figure out which way to join things. I have a parts_invoice_header table, containing the header record for each invoice. I have a parts_invoice_lines table, containing the parts details for each invoice. I have a parts_invoice_sundries table, containing additional sundry charges (freight, delivery etc) on each invoice. For each record in the invoice_header table, there can be 0 or more records in either of the two other tables. I want to search for an invoice in the header file and get the details of all matching records from the lines and sundries. Assuming the lines and sundries tables both have the same column names, I should be able to end up with something like: table | header header line/sundries | column| Invoice number customer item amount line | 1111 abc 457ABC 10.00 sundry| 1111 abc FREIGHT 5.00 line | 1111 abc FGOIL 15.00 What would be the best method of joining to create a result-set such as this? TIA for any assistance, P. -- Paul Lambert Database Administrator AutoLedgers