Re: Efficiently obtaining (any) one record per group.

From: Scott Marlowe <scott(dot)marlowe(at)gmail(dot)com>
To: Allan Kamau <kamauallan(at)gmail(dot)com>
Cc: Postgres General Postgres General <pgsql-general(at)postgresql(dot)org>
Subject: Re: Efficiently obtaining (any) one record per group.
Date: 2010-07-24 07:38:43
Message-ID: AANLkTimLuEhDOPC_Z=GMcymasETv5Hmww1=6rRT8-E20@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Sat, Jul 24, 2010 at 12:56 AM, Allan Kamau <kamauallan(at)gmail(dot)com> wrote:
> Hi all,
>
> I have a large table that contains redundancies as per one field.
>
> I am looking for a way to identify (or extract) a non redundant set of
> rows ( _any_ one record per group) from this table and for each record
> of this "distinct" set of rows, I would like to capture it's other
> fields.

Would "Select distinct on ... " work for you?

http://www.postgresql.org/docs/8.4/static/sql-select.html

search the page for "distinct on".

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Alban Hertroys 2010-07-24 10:08:23 Re: Blocked inserts on tables with FK to tables for which UPDATE has been revoked
Previous Message Allan Kamau 2010-07-24 06:56:26 Efficiently obtaining (any) one record per group.