Re: problem with sql

From: Michael Glaesmann <grzm(at)myrealbox(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: problem with sql
Date: 2003-10-25 11:06:05
Message-ID: 3A8501C8-06DB-11D8-B941-0005029FC1A7@myrealbox.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Neil Zanella 2003-10-26 03:30:25 defining and using constants in postgreSQL
Previous Message Julian North 2003-10-25 09:41:02 Re: naming conventions constraint