Received: from megamail.dsl.net (megamail.dsl.net [209.87.64.97]) by postgresql.org (8.11.3/8.11.1) with ESMTP id f6GIQwa57954 for ; Mon, 16 Jul 2001 14:26:58 -0400 (EDT) (envelope-from james@lrgmail.com) Received: from jameslt (64-51-205-180.client.dsl.net [64.51.205.180]) by megamail.dsl.net (8.9.3/8.9.3) with SMTP id OAA15990 for ; Mon, 16 Jul 2001 14:26:56 -0400 Message-ID: <009b01c10e25$9a625940$1600000a@lrg.office> From: "James Orr" To: References: Subject: Re: Help with SQL statement - Thanks Date: Mon, 16 Jul 2001 14:31:30 -0400 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 5.50.4522.1200 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200 X-Archive-Number: 200107/206 X-Sequence-Number: 4002 SELECT * FROM Payments P1 WHERE Date = (SELECT MAX(Date) FROM Payments P2 WHERE P2.CustomerNo = P1.CustomerNo) I think that will do it. - James ----- Original Message ----- From: "Henry" To: Sent: Saturday, July 14, 2001 3:16 PM Subject: [SQL] Help with SQL statement - Thanks > There is a table called "Payments" which records every payment that a > company has received: > > CustomerNo Date Amount > ---------------------------------------- > 3214 2/12 30 > 3214 4/10 50 > 9943 4/18 40 > 9943 5/10 30 > 9943 2/13 70 > 1121 5/23 10 > 1121 4/20 40 > 1121 3/12 30 > (more data...) > > > I want to be able to pull out the last payment made by everyone in a query: > > CustomerNo Date Amount > --------------------------------------- > 3214 4/10 50 > 9943 5/10 30 > 1121 5/23 10 > (other users...) > > How should I write the SQL statement? Please email to me at > henry_lu@hotmail.com. Thank you very much. > > Henry > > > > > ---------------------------(end of broadcast)--------------------------- > TIP 6: Have you searched our list archives? > > http://www.postgresql.org/search.mpl >