Re: SQL problem: bank account - Mailing list pgsql-sql

From Jonathan Gardner
Subject Re: SQL problem: bank account
Date
Msg-id 200306020940.58614.jgardner@jonathangardner.net
Whole thread Raw
In response to Re: SQL problem: bank account  ("listrec" <listrec@epecon.de>)
List pgsql-sql
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_idFROM bank_accountGROUP 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!


pgsql-sql by date:

Previous
From: Samuel Tardieu
Date:
Subject: Maintaining a counter up-to-date
Next
From: Jonathan Gardner
Date:
Subject: Re: SQL problem: bank account