Re: problem with sql - Mailing list pgsql-sql

From Michael Glaesmann
Subject Re: problem with sql
Date
Msg-id 3A8501C8-06DB-11D8-B941-0005029FC1A7@myrealbox.com
Whole thread Raw
In response to problem with sql  (Adaś <adamn@qwe.pl>)
List pgsql-sql
Hi Adam,

On Monday, Oct 20, 2003, at 01:56 Asia/Tokyo, Adaś wrote:
> status. I made a query using LAST and GROUP BY to select last order
> for each customer and I wanted to use it in UPDATE query, but it seems
> to be impossible.

I don't believe PostgreSQL has a built-in function similar to MS
Access' LAST. Something like the following might work for you:

SELECT DISTINCT ON (client) client, order_number, order_date FROM
orders ORDER BY order_date desc

You might have to change the DISTINCT ON terms to match what you want.
Check the docs for usage of DISTINCT ON.

Also, I've heard it's quite easy to write a custom function to do what
you want using CREATE FUNCTION. Haven't done it myself.

Hope it helps.

Michael


pgsql-sql by date:

Previous
From: Joe Conway
Date:
Subject: Re: Referring to derived column name in a RECORD
Next
From: "Julian North"
Date:
Subject: Re: naming conventions constraint