From: Michael Glaesmann <grzm@myrealbox.com>
To: pgsql-sql@postgresql.org
Subject: Re: problem with sql
Date: Sat, 25 Oct 2003 20:06:05 +0900
Message-ID: <3A8501C8-06DB-11D8-B941-0005029FC1A7@myrealbox.com> (raw)
In-Reply-To: <Kmzkb.25189$bU3.325187@news.chello.at>
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-sql@postgresql.org
Cc: grzm@myrealbox.com
Subject: Re: problem with sql
In-Reply-To: <3A8501C8-06DB-11D8-B941-0005029FC1A7@myrealbox.com>
References: <Kmzkb.25189$bU3.325187@news.chello.at> <3A8501C8-06DB-11D8-B941-0005029FC1A7@myrealbox.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox