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 93A90D1B1D5 for ; Wed, 7 Jul 2004 01:48:53 -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 64350-06 for ; Wed, 7 Jul 2004 04:48:51 +0000 (GMT) Received: from mail.iinet.net.au (mail-02.iinet.net.au [203.59.3.34]) by svr1.postgresql.org (Postfix) with SMTP id 40372D1B174 for ; Wed, 7 Jul 2004 01:48:46 -0300 (ADT) Received: (qmail 2918 invoked from network); 7 Jul 2004 04:46:25 -0000 Received: from unknown (HELO langtree.ideloveto) (203.217.28.254) by mail.iinet.net.au with SMTP; 7 Jul 2004 04:46:24 -0000 Received: from langtree.ideloveto (localhost.ideloveto [127.0.0.1]) by langtree.ideloveto (8.12.10/8.12.10) with ESMTP id i674chvq023074 for ; Wed, 7 Jul 2004 14:38:43 +1000 (EST) (envelope-from david.inglis@ideloveto.com.au) Received: (from nobody@localhost) by langtree.ideloveto (8.12.10/8.12.10/Submit) id i674cgM1023073 for pgsql-sql@postgresql.org; Wed, 7 Jul 2004 14:38:42 +1000 (EST) (envelope-from david.inglis@ideloveto.com.au) X-Authentication-Warning: langtree.ideloveto: nobody set sender to david.inglis@ideloveto.com.au using -f Received: from 192.168.1.254 ([192.168.1.254]) by www.sportsupdate.com.au (IMP) with HTTP for ; Wed, 7 Jul 2004 14:38:42 +1000 Message-ID: <1089175122.40eb7e520e8d2@www.sportsupdate.com.au> Date: Wed, 7 Jul 2004 14:38:42 +1000 From: David Inglis To: pgsql-sql@postgresql.org Subject: Help with sql statement grouping and distinct MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit User-Agent: Internet Messaging Program (IMP) 3.2.3 X-Originating-IP: 192.168.1.254 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=2.2 tagged_above=0.0 required=5.0 tests=RCVD_IN_BL_SPAMCOP_NET X-Spam-Level: ** X-Archive-Number: 200407/51 X-Sequence-Number: 18303 I want to be able to select a distinct group of rows from 2 tables and then once selected to group and total the results from the previous sql statement I have been trying the following select a.id_fk_accommodation, a.id_fk_selection,a.type,sum(1) from acommodationlog a, log l where (id_fk_accommodation) in (select distinct a.id_fk_accommodation, a.id_fk_selection, a.type, l.sessionid from accommodationlog a, log l where a.id_fk_log = l.id_pk and id_fk_accommodation = 159 ) group by a.id_fk_accommodation,a.id_fk_selection,a.type I know this won't work due to incorrect number of columns in the in statement but how do I achieve the above Any help appreciated Thanks Regards David Inglis ---------------------------------------------------------------- This message was sent using IMP, the Internet Messaging Program.