X-Original-To: pgsql-sql@postgresql.org Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 89301475957 for ; Fri, 7 Feb 2003 05:09:58 -0500 (EST) Received: from stan.ringways.co.uk (hub.ringways.co.uk [213.38.87.130]) by postgresql.org (Postfix) with ESMTP id CDFBD475956 for ; Fri, 7 Feb 2003 05:09:47 -0500 (EST) Received: from gary.ringways.co.uk ([10.1.1.2]) by stan.ringways.co.uk with esmtp (Exim 3.22 #1) id 18h5Zq-0004sk-00 for pgsql-sql@postgresql.org; Fri, 07 Feb 2003 10:17:46 +0000 Content-Type: text/plain; charset="us-ascii" From: Gary Stainburn Organization: Ringways Garages Ltd To: pgsql-sql@postgresql.org Subject: efficient count/join query Date: Fri, 7 Feb 2003 10:07:28 +0000 User-Agent: KMail/1.4.3 MIME-Version: 1.0 Message-Id: <200302071007.28697.gary.stainburn@ringways.co.uk> Content-Transfer-Encoding: quoted-printable X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200302/146 X-Sequence-Number: 11544 Hi folks, I've got two tables, first a history table containing tallies for staff/job= s=20 prior to going live, and second a roster table showing date, diagram, job= =20 with one record per person per job per day. the tables are: create table history ( hsid int4 not null references staff(sid), hjid int4 not null references jobs(jid), hcount int4, primary key (hsid,hjid)); create table roster ( rodate date not null, rogid int4 not null references diagrams(gid), rojid int4 not null references jobs(jid), rosid int4 references staff(sid), primary key (rodate, rogid, rojid)); What's the best/quickest/cheapest way to create a view in the format of the= =20 history table but including the details from the roster table for all recor= ds=20 prior to today. I've been looking at some form of sub-select/join scheme but as some will o= nly=20 exist on the history and some will only exist on the roster while many will= =20 exist on both. --=20 Gary Stainburn =20 This email does not contain private or confidential material as it may be snooped on by interested government parties for unknown and undisclosed purposes - Regulation of Investigatory Powers Act, 2000=20= =20=20=20=20