pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Erik G. Burrows <eburrows@erikburrows.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: SQL problem: bank account
Date: Mon, 02 Jun 2003 09:42:37 -0400
Message-ID: <7888.1054561357@sss.pgh.pa.us> (raw)
In-Reply-To: <1054531815.13212.27.camel@griffin.jedi-group.com>
References: <1054531815.13212.27.camel@griffin.jedi-group.com>

"Erik G. Burrows" <eburrows@erikburrows.com> writes:
> I need to get the most recent transaction for each customer. I need only
> the transaction ID, but the entire row would be best.

If you don't mind a not-standard-SQL solution, the SELECT DISTINCT ON
construct is designed for this sort of thing.  See the "weather report"
example in the SELECT reference page.

			regards, tom lane



view thread (9+ messages)  latest in thread

Message-ID: <7888.1054561357@sss.pgh.pa.us>
Permalink:  ../7888.1054561357@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/7888.1054561357@sss.pgh.pa.us

 · 

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: tgl@sss.pgh.pa.us, eburrows@erikburrows.com
  Subject: Re: SQL problem: bank account
  In-Reply-To: <7888.1054561357@sss.pgh.pa.us>

* 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