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

From: Allan Kamau <kamauallan(at)gmail(dot)com>
To: Postgres General Postgres General <pgsql-general(at)postgresql(dot)org>
Subject: Re: Efficiently obtaining (any) one record per group.
Date: 2010-07-24 10:08:56
Message-ID: AANLkTi=dfY9RS9DU5r58qOYBB9i7XxR8g9j6ZOBT8QqK@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Sat, Jul 24, 2010 at 10:38 AM, Scott Marlowe <scott(dot)marlowe(at)gmail(dot)com> wrote:
> 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".
>

Thank you Scott, you have made my day, this is exactly what I was looking for.

Allan.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Alban Hertroys 2010-07-24 10:26:02 Re: Prefix LIKE search and indexes issue.
Previous Message Alban Hertroys 2010-07-24 10:08:23 Re: Blocked inserts on tables with FK to tables for which UPDATE has been revoked