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 537489264AA for ; Mon, 2 Jun 2003 13:04:27 -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 33587-06 for ; Mon, 2 Jun 2003 13:04:16 -0400 (EDT) Received: from griffin.jedi-group.com (unknown [64.58.182.208]) by developer.postgresql.org (Postfix) with ESMTP id 326BA9264E3 for ; Mon, 2 Jun 2003 12:58:43 -0400 (EDT) Received: (from eburrows@localhost) by griffin.jedi-group.com (8.11.6/8.11.6) id h52Gwdf18148; Mon, 2 Jun 2003 09:58:39 -0700 X-Authentication-Warning: griffin.jedi-group.com: eburrows set sender to eburrows@erikburrows.com using -f Subject: Re: SQL problem: bank account From: "Erik G. Burrows" To: Tom Lane Cc: pgsql-sql@postgresql.org In-Reply-To: <7888.1054561357@sss.pgh.pa.us> References: <1054531815.13212.27.camel@griffin.jedi-group.com> <7888.1054561357@sss.pgh.pa.us> Content-Type: text/plain Content-Transfer-Encoding: 7bit Organization: Message-Id: <1054573119.13212.41.camel@griffin.jedi-group.com> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.2.2 Date: 02 Jun 2003 09:58:39 -0700 X-Virus-Scanned: by amavisd-new X-Archive-Number: 200306/23 X-Sequence-Number: 13781 This is the solution I was looking for! 20 seconds to compile the whole list. Thanks everyone for your help, I very much appreciate it. Even though this is kind of 'hackey' being that it's non-standard SQL, it keeps the database from having to to 40,000 selects, as would have to do with any correlated sub-select statement. Thanks! > "Erik G. Burrows" 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 > > ---------------------------(end of broadcast)--------------------------- > TIP 5: Have you checked our extensive FAQ? > > http://www.postgresql.org/docs/faqs/FAQ.html -- Erik G. Burrows - KG6HEA www.erikburrows.com PGP Key: http://www.erikburrows.com/egb@erikburrows.com.pgpkey