pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Jonathan Gardner <jgardner@jonathangardner.net>
To: listrec <listrec@epecon.de>
To: Erik G. Burrows <eburrows@erikburrows.com>
To: pgsql-sql@postgresql.org
Subject: Re: SQL problem: bank account
Date: Mon, 2 Jun 2003 09:40:58 -0700
Message-ID: <200306020940.58614.jgardner@jonathangardner.net> (raw)
In-Reply-To: <PCEJJIGCHIJCOOOGFAFEKENBCAAA.listrec@epecon.de>
References: <PCEJJIGCHIJCOOOGFAFEKENBCAAA.listrec@epecon.de>

On Monday 02 June 2003 00:49, listrec wrote:
> How about:
>
> select max(transaction_id) from bank_account group by customer_id
>

And if you want the rest of the data in the rows:

SELECT b.*
FROM bank_account b
JOIN  (
	SELECT max(transaction_id) AS transaction_id
	FROM bank_account
	GROUP BY customer_id
) AS subselect ON subselect.transaction_id=b.transaction_id
;

I use a similar query here at work to find the first time a guy has visited 
our site through an advertiser.

-- 
Jonathan Gardner <jgardner@jonathangardner.net>
(was jgardn@alumni.washington.edu)
Live Free, Use Linux!



view thread (9+ messages)  latest in thread

Message-ID: <200306020940.58614.jgardner@jonathangardner.net>
Permalink:  ../200306020940.58614.jgardner@jonathangardner.net/
Also on:    postgresql.org/message-id/200306020940.58614.jgardner@jonathangardner.net

 · 

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: jgardner@jonathangardner.net, listrec@epecon.de, eburrows@erikburrows.com
  Subject: Re: SQL problem: bank account
  In-Reply-To: <200306020940.58614.jgardner@jonathangardner.net>

* 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