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 49AAF528B4 for ; Thu, 23 Jun 2005 17:03:49 -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 35794-02 for ; Thu, 23 Jun 2005 20:03:45 +0000 (GMT) Received: from hotmail.com (bay103-f8.bay103.hotmail.com [65.54.174.18]) by svr1.postgresql.org (Postfix) with ESMTP id DBCBF52817 for ; Thu, 23 Jun 2005 17:03:43 -0300 (ADT) Received: from mail pickup service by hotmail.com with Microsoft SMTPSVC; Thu, 23 Jun 2005 13:03:45 -0700 Message-ID: Received: from 65.54.174.204 by by103fd.bay103.hotmail.msn.com with HTTP; Thu, 23 Jun 2005 20:03:45 GMT X-Originating-IP: [65.54.174.204] X-Originating-Email: [russellsimpkins@hotmail.com] X-Sender: russellsimpkins@hotmail.com In-Reply-To: From: "Russell Simpkins" To: tfo@sitening.com, pgsql-sql@postgresql.org Subject: Re: Grouping Too Closely Date: Thu, 23 Jun 2005 16:03:45 -0400 Mime-Version: 1.0 Content-Type: text/plain; format=flowed X-OriginalArrivalTime: 23 Jun 2005 20:03:45.0795 (UTC) FILETIME=[A986F530:01C5782E] X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=1.373 tagged_above=0 required=5 tests=AWL, DNS_FROM_RFC_ABUSE, DNS_FROM_RFC_POST, MSGID_FROM_MTA_HEADER X-Spam-Level: * X-Archive-Number: 200506/284 X-Sequence-Number: 21885 I'm not sure if this is the best thing to do in all occasions, but I have found a great speed increase using unions over group by. select fkey, uid, seq2 from mytable where seq2 > 2 and seq1 = ( select min(seq1) from mytable); union select fkey, uid, seq2 from mytable where seq2 > 2 and seq1 = ( select min(seq1) from mytable); order by fkey, uid, seq2; the union clause with remove your duplicates for you as you were doing with your group by. using min on large tables can cause problems. you may want to do your select min(seq1) from mytable or even have a trigger function after insert/update that checks the new value against the current lowest stored in another table. not sure if this helps, but i hope it does. russ