X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id DCC57D1B50E for ; Sat, 25 Oct 2003 11:06:42 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 94209-06 for ; Sat, 25 Oct 2003 08:06:14 -0300 (ADT) Received: from smtp-send.myrealbox.com (smtp-send.myrealbox.com [192.108.102.143]) by svr1.postgresql.org (Postfix) with ESMTP id 0EB10D1B504 for ; Sat, 25 Oct 2003 08:06:11 -0300 (ADT) Received: from myrealbox.com grzm@smtp-send.myrealbox.com [211.131.91.154] by smtp-send.myrealbox.com with NetMail SMTP Agent $Revision: 3.42 $ on Novell NetWare; Sat, 25 Oct 2003 05:06:13 -0600 Date: Sat, 25 Oct 2003 20:06:05 +0900 Subject: Re: problem with sql Content-Type: text/plain; charset=ISO-8859-2; format=flowed Mime-Version: 1.0 (Apple Message framework v552) From: Michael Glaesmann To: pgsql-sql@postgresql.org Content-Transfer-Encoding: quoted-printable In-Reply-To: Message-Id: <3A8501C8-06DB-11D8-B941-0005029FC1A7@myrealbox.com> X-Mailer: Apple Mail (2.552) X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200310/332 X-Sequence-Number: 15732 Hi Adam, On Monday, Oct 20, 2003, at 01:56 Asia/Tokyo, Ada=B6 wrote: > status. I made a query using LAST and GROUP BY to select last order=20 > for each customer and I wanted to use it in UPDATE query, but it seems=20 > to be impossible. I don't believe PostgreSQL has a built-in function similar to MS=20 Access' LAST. Something like the following might work for you: SELECT DISTINCT ON (client) client, order_number, order_date FROM=20 orders ORDER BY order_date desc You might have to change the DISTINCT ON terms to match what you want.=20 Check the docs for usage of DISTINCT ON. Also, I've heard it's quite easy to write a custom function to do what=20 you want using CREATE FUNCTION. Haven't done it myself. Hope it helps. Michael