pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Michael Fuhr <mike@fuhr.org>
To: q2005 <q2005@tpg.com.au>
Cc: pgsql-sql@postgresql.org
Subject: Re: the best way  to get the first record from each group
Date: Mon, 7 Feb 2005 18:16:26 -0700
Message-ID: <20050208011626.GA43996@winnie.fuhr.org> (raw)
In-Reply-To: <005201c50d76$33dbec00$1400a8c0@jac>
References: <005201c50d76$33dbec00$1400a8c0@jac>

On Tue, Feb 08, 2005 at 10:36:17AM +1000, q2005 wrote:
>
> Is there any better alternative to get the first record from each group?

PostgreSQL has a non-standard SELECT DISTINCT ON query for just
this purpose.

http://www.postgresql.org/docs/8.0/static/queries-select-lists.html#QUERIES-DISTINCT
http://www.postgresql.org/docs/8.0/static/sql-select.html#SQL-DISTINCT

-- 
Michael Fuhr
http://www.fuhr.org/~mfuhr/



view thread (5+ messages)  latest in thread

Message-ID: <20050208011626.GA43996@winnie.fuhr.org>
Permalink:  ../20050208011626.GA43996@winnie.fuhr.org/
Also on:    postgresql.org/message-id/20050208011626.GA43996@winnie.fuhr.org

 · 

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 using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: mike@fuhr.org, q2005@tpg.com.au
  Subject: Re: the best way  to get the first record from each group
  In-Reply-To: <20050208011626.GA43996@winnie.fuhr.org>

* 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