X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 3198352D75 for ; Fri, 15 Jul 2005 06:00:57 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 87860-05 for ; Fri, 15 Jul 2005 09:00:46 +0000 (GMT) Received: from mail.metronet.co.uk (mail.metronet.co.uk [213.162.97.75]) by svr1.postgresql.org (Postfix) with ESMTP id 300FD52D71 for ; Fri, 15 Jul 2005 06:00:44 -0300 (ADT) Received: from mainbox.archonet.com (84-51-143-99.archon037.adsl.metronet.co.uk [84.51.143.99]) by smtp.metronet.co.uk (MetroNet Mail) with ESMTP id 700C540DB97; Fri, 15 Jul 2005 10:00:39 +0100 (BST) Received: from localhost (localhost.localdomain [127.0.0.1]) by mainbox.archonet.com (Postfix) with ESMTP id 5FAC815EE9; Fri, 15 Jul 2005 09:57:40 +0100 (BST) Received: from mainbox.archonet.com ([127.0.0.1]) by localhost (mainbox [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 27747-10; Fri, 15 Jul 2005 09:57:37 +0100 (BST) Received: from [192.168.1.17] (client17.office.archonet.com [192.168.1.17]) by mainbox.archonet.com (Postfix) with ESMTP id 1C57215EE1; Fri, 15 Jul 2005 09:57:37 +0100 (BST) Message-ID: <42D77A80.6060101@archonet.com> Date: Fri, 15 Jul 2005 09:57:36 +0100 From: Richard Huxton User-Agent: Mozilla Thunderbird 1.0.2 (X11/20050317) X-Accept-Language: en-us, en MIME-Version: 1.0 To: spinto@virtualslo.com Cc: pgsql-sql@postgresql.org Subject: Re: Help With complex join References: <1121376842.249209.127400@z14g2000cwz.googlegroups.com> In-Reply-To: <1121376842.249209.127400@z14g2000cwz.googlegroups.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.056 tagged_above=0 required=5 tests=AWL, FORGED_RCVD_HELO X-Spam-Level: X-Archive-Number: 200507/135 X-Sequence-Number: 22113 spinto@virtualslo.com wrote: > Hi all, got a question as how to approach a somewhat complicated join > query. The deal is I have three tables called attorney, lawOffice, and > law_office_employment. The attorney and lawOffice tables hold attorney > and lawOffice information respectively (obviously). The > law_office_employment table is meant to show historical periods of time > for which the attorney's worked for the different lawOffices. But it doesn't. Looking below, it shows the date they started in each law office, not the period they worked there. In fact, you can't capture a period of unemployment/sabbatical using just this table. > Here is > the create table statement for law_office_employment: > > /*==============================================================*/ > /* Table: LAW_OFFICE_EMPLOYMENT */ > /*==============================================================*/ > create table LAW_OFFICE_EMPLOYMENT ( > ATTORNEYID IDENTIFIER not null, > LAWOFFICEID IDENTIFIER not null, > STARTDATE DATE not null, > constraint PK_LAW_OFFICE_EMPLOYMENT primary key (ATTORNEYID, > LAWOFFICEID, STARTDATE) > ); Make your life easier and have start and end-dates. Oh, you might want a "finished-here" flag too to indicate the end-date can be checked. -- Richard Huxton Archonet Ltd