X-Original-To: pgsql-sql@postgresql.org Received: from localhost (developer.postgresql.org [64.117.224.193]) by developer.postgresql.org (Postfix) with ESMTP id AEB42926436 for ; Mon, 2 Jun 2003 12:41:15 -0400 (EDT) Received: from developer.postgresql.org ([64.117.224.193]) by localhost (developer.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 22499-09 for ; Mon, 2 Jun 2003 12:41:05 -0400 (EDT) Received: from irko.smoothcorp.com (unknown [208.49.241.41]) by developer.postgresql.org (Postfix) with ESMTP id 55E9D9263F0 for ; Mon, 2 Jun 2003 12:41:03 -0400 (EDT) Received: from jgardner.ifloor.com ([10.0.1.63]) by irko.smoothcorp.com with esmtp (Exim 4.12) id 19MsMl-0001AK-00; Mon, 02 Jun 2003 09:40:59 -0700 Received: from jgardner.ifloor.com (localhost.localdomain [127.0.0.1]) by jgardner.ifloor.com (8.12.8/8.12.8) with ESMTP id h52Gf0au032295; Mon, 2 Jun 2003 09:41:00 -0700 Received: from localhost (localhost [[UNIX: localhost]]) by jgardner.ifloor.com (8.12.8/8.12.8/Submit) id h52Gewnh032293; Mon, 2 Jun 2003 09:40:58 -0700 From: Jonathan Gardner To: "listrec" , "Erik G. Burrows" , Subject: Re: SQL problem: bank account Date: Mon, 2 Jun 2003 09:40:58 -0700 User-Agent: KMail/1.5 References: In-Reply-To: MIME-Version: 1.0 Content-Disposition: inline Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <200306020940.58614.jgardner@jonathangardner.net> X-SA-Exim-Rcpt-To: listrec@epecon.de, eburrows@erikburrows.com, pgsql-sql@postgresql.org X-SA-Exim-Scanned: No; SAEximRunCond expanded to false X-Virus-Scanned: by amavisd-new X-Archive-Number: 200306/21 X-Sequence-Number: 13779 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 (was jgardn@alumni.washington.edu) Live Free, Use Linux!