Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 4E9BB4758C9 for ; Fri, 20 Dec 2002 05:53:24 -0500 (EST) Received: from acheron.rime.com.au (unknown [203.208.66.49]) by postgresql.org (Postfix) with ESMTP id 8CF494758BD for ; Fri, 20 Dec 2002 05:53:23 -0500 (EST) Received: from localhost (localhost [127.0.0.1]) by acheron.rime.com.au (Postfix on SuSE Linux 8.0 (i386)) with ESMTP id 1C0D95457F; Fri, 20 Dec 2002 21:53:24 +1100 (EST) Received: by acheron.rime.com.au (Postfix on SuSE Linux 8.0 (i386), from userid 527) id 129E754580; Fri, 20 Dec 2002 21:53:23 +1100 (EST) Received: from hephaestus.rhyme.com.au (unknown [203.8.195.124]) by acheron.rime.com.au (Postfix on SuSE Linux 8.0 (i386)) with ESMTP id 823E05457F; Fri, 20 Dec 2002 21:53:22 +1100 (EST) Message-Id: <5.1.0.14.0.20021220214822.02d7e360@mail.rhyme.com.au> X-Sender: pjw@mail.rhyme.com.au X-Mailer: QUALCOMM Windows Eudora Version 5.1 Date: Fri, 20 Dec 2002 21:51:19 +1100 To: Gary Stainburn , pgsql-sql@postgresql.org From: Philip Warner Subject: Re: Help on (sub)-select In-Reply-To: <200212201021.50475.gary.stainburn@ringways.co.uk> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; format=flowed X-Spam-Status: No, hits=-3.1 required=8.5 tests=IN_REP_TO,WEIRD_PORT version=2.31 X-Spam-Level: X-Virus-Scanned: by AMaViS 0.3.12pre8 X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200212/246 X-Sequence-Number: 10834 At 10:21 AM 20/12/2002 +0000, Gary Stainburn wrote: >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) Try something like: select r.*, count(*) from roster r, roster_staff s where rsdate = rodate and rsgid = rogid and rsgsid = rogid group by r.* or select r.*, (select count(*) from roster_staff s where rsdate = rodate and rsgid = rogid and rsgsid = rogid ) roster r May not be exactly right, but you should get the idea ---------------------------------------------------------------- Philip Warner | __---_____ Albatross Consulting Pty. Ltd. |----/ - \ (A.B.N. 75 008 659 498) | /(@) ______---_ Tel: (+61) 0500 83 82 81 | _________ \ Fax: (+61) 03 5330 3172 | ___________ | Http://www.rhyme.com.au | / \| | --________-- PGP key available upon request, | / and from pgp5.ai.mit.edu:11371 |/