Re: Q: select query - Mailing list pgsql-sql

From Manfred Koizar
Subject Re: Q: select query
Date
Msg-id s0p6mv8a7bkf7fjsgo4hlcr8co0l1845j7@email.aon.at
Whole thread Raw
In response to Q: select query  (grk@usa.net (G. Ralph Kuntz, MD))
List pgsql-sql
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) ...);

ServusManfred


pgsql-sql by date:

Previous
From: Rod Taylor
Date:
Subject: Re: Q: select query
Next
From: chester c young
Date:
Subject: sorting