X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id A675DD1B53A for ; Sat, 13 Sep 2003 18:50:31 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 64850-10 for ; Sat, 13 Sep 2003 15:50:01 -0300 (ADT) Received: from email02.aon.at (WARSL402PIP7.highway.telekom.at [195.3.96.94]) by svr1.postgresql.org (Postfix) with SMTP id 08C85D1B4F1 for ; Sat, 13 Sep 2003 15:49:59 -0300 (ADT) Received: (qmail 40914 invoked from network); 13 Sep 2003 18:49:58 -0000 Received: from m156p006.dipool.highway.telekom.at (HELO cantor) ([62.46.9.102]) (envelope-sender ) by qmail2rs.highway.telekom.at (qmail-ldap-1.03) with SMTP for ; 13 Sep 2003 18:49:58 -0000 From: Manfred Koizar To: grk@usa.net (G. Ralph Kuntz, MD) Cc: pgsql-sql@postgresql.org Subject: Re: Q: select query Date: Sat, 13 Sep 2003 20:52:02 +0200 Message-ID: References: <9881c752.0309120958.454c659c@posting.google.com> In-Reply-To: <9881c752.0309120958.454c659c@posting.google.com> X-Mailer: Forte Agent 1.93/32.576 English (American) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200309/108 X-Sequence-Number: 15086 On 12 Sep 2003 10:58:45 -0700, grk@usa.net (G. Ralph Kuntz, MD) wrote: >I would like to select the second and subsequent rows where the first >column is the same: > > 1 b > 1 c > 3 f > >in other words, all but the first row of a group. all = SELECT * FROM t; but = EXCEPT the first row of a group = SELECT i, min(x) FROM t GROUP BY i; or (if there are more columns) SELECT DISTINCT ON(i) * FROM t ORDER BY i, x; Putting it together: SELECT i, x FROM t EXCEPT (SELECT i, min(x) FROM t GROUP BY i); or SELECT * FROM t EXCEPT (SELECT DISTINCT ON(i) ...); Servus Manfred