Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 01896475B33 for ; Fri, 20 Dec 2002 05:27:52 -0500 (EST) Received: from stan.ringways.co.uk (hub.ringways.co.uk [213.38.87.130]) by postgresql.org (Postfix) with ESMTP id 4E00C4758BD for ; Fri, 20 Dec 2002 05:27:51 -0500 (EST) Received: from gary.ringways.co.uk ([10.1.1.2]) by stan.ringways.co.uk with esmtp (Exim 3.22 #1) id 18PKMh-0001Le-00 for pgsql-sql@postgresql.org; Fri, 20 Dec 2002 10:26:47 +0000 Content-Type: text/plain; charset="us-ascii" From: Gary Stainburn Organization: Ringways Garages Ltd To: pgsql-sql@postgresql.org Subject: Help on (sub)-select Date: Fri, 20 Dec 2002 10:21:50 +0000 User-Agent: KMail/1.4.3 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-Id: <200212201021.50475.gary.stainburn@ringways.co.uk> X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200212/245 X-Sequence-Number: 10833 Hi Folks, I have two tables roster holds the duties to be performed and the number of people required per duty. roster_staff holds the people allocated to perform that duty. I'm trying to create a select that will tally the roster_staff and include it with the roster details. I've managed to get it working for a specific day, but I can't seem to manage to get it working generically. here's the select I've got that works, along with the output: nymr=# select r.*, s.tally from roster r, nymr-# (select count(*) as tally from roster_staff where nymr(# rsdate = '2002-01-01' and rsgid = 11 and rsgsid = 2) as s nymr-# where rodate = '2002-01-01' and rogid = 11 and rogsid = 2; rodate | rogid | rogsid | rorequired | rooptional | tally ------------+-------+--------+------------+------------+------- 2002-01-01 | 11 | 2 | 0 | 1 | 2 (1 row) nymr=# What I want to be able to do is select multiple rows and have the correct tally appear for that row. -- Gary Stainburn 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