X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id E70539FA3A6 for ; Tue, 6 Jun 2006 20:40:36 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 29172-01 for ; Tue, 6 Jun 2006 20:40:32 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from web31807.mail.mud.yahoo.com (web31807.mail.mud.yahoo.com [68.142.207.70]) by postgresql.org (Postfix) with SMTP id A38AD9FA0E5 for ; Tue, 6 Jun 2006 20:40:33 -0300 (ADT) Received: (qmail 170 invoked by uid 60001); 6 Jun 2006 23:40:31 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=Message-ID:Received:Date:From:Subject:To:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=JwYHaVBhHANpi1jIbwAAmXngMAhJZd78a4rWqpNE/znVMUnHZYVPxco0n57kf0TxLev9hOAF7fZeN8zXb9Tkvb0nAutKgNq/qqb3XVCOX1XniKjx5nhKgiystbmq0iJ7JItKTs82EV15UDptLK3yKXDPMxeYepvwyF+OIK8YHlM= ; Message-ID: <20060606234031.168.qmail@web31807.mail.mud.yahoo.com> Received: from [68.235.218.116] by web31807.mail.mud.yahoo.com via HTTP; Tue, 06 Jun 2006 16:40:31 PDT Date: Tue, 6 Jun 2006 16:40:31 -0700 (PDT) From: Richard Broersma Jr Subject: Re: How To Exclude True Values To: operationsengineer1@yahoo.com, "pgsql-sql@postgresql.org" In-Reply-To: <20060606230141.3017.qmail@web33310.mail.mud.yahoo.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200606/79 X-Sequence-Number: 25315 > Richard, that is the result i would need given that > data set. i have to digest this version, though. > > should this query be more efficient than the subquery > version as the table starts to get large? My experience is that Distinct On queries do not preform as well as their group by counter parts. I believe that others have also commented to the same effect. To speed the query you could apply indexes on the group by fields and the join columns. Also, I produced a second query using PostgreSQL: select a.id_i, a.ir_id, a.test, a.stamp from test a join ( select max(stamp) as mstamp, id_i from test group by id_i ) b on a.stamp = b.mstamp where a.test = false ; -- result id_i | ir_id | test | stamp ------+-------+------+--------------------- 4 | 8 | f | 2006-06-05 08:00:00