pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Manfred Koizar <mkoi-pg@aon.at>
To: grk@usa.net
Cc: pgsql-sql@postgresql.org
Subject: Re: Q: select query
Date: Sat, 13 Sep 2003 20:52:02 +0200
Message-ID: <s0p6mv8a7bkf7fjsgo4hlcr8co0l1845j7@email.aon.at> (raw)
In-Reply-To: <9881c752.0309120958.454c659c@posting.google.com>
References: <9881c752.0309120958.454c659c@posting.google.com>

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



view thread (3+ messages)

Message-ID: <s0p6mv8a7bkf7fjsgo4hlcr8co0l1845j7@email.aon.at>
Permalink:  ../s0p6mv8a7bkf7fjsgo4hlcr8co0l1845j7@email.aon.at/
Also on:    postgresql.org/message-id/s0p6mv8a7bkf7fjsgo4hlcr8co0l1845j7@email.aon.at

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: mkoi-pg@aon.at, grk@usa.net
  Subject: Re: Q: select query
  In-Reply-To: <s0p6mv8a7bkf7fjsgo4hlcr8co0l1845j7@email.aon.at>
  References: <9881c752.0309120958.454c659c@posting.google.com> <s0p6mv8a7bkf7fjsgo4hlcr8co0l1845j7@email.aon.at>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox