Re: Help with a complex Update

From: "Josh Berkus" <josh(at)agliodbs(dot)com>
To: o2(at)trustcommerce(dot)com, pgsql-sql(at)postgresql(dot)org
Subject: Re: Help with a complex Update
Date: 2001-11-05 16:57:10
Message-ID: web-498968@davinci.ethosmedia.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Orion,

> update user_info set first_action = (select min(action_timestamp)
> from
> action_info where user_id = ?? current user id ??);

Close. You need to use a subselect in the FROM clause:

UPDATE user_info SET first_action = min_action
FROM (select user_id, min(action_timestamp) as min_action
FROM action_info WHERE user_id = $user_variable
GROUP BY user_id) ma
WHERE user_info.user_id = ma.user_id;

-Josh

______AGLIO DATABASE SOLUTIONS___________________________
Josh Berkus
Complete information technology josh(at)agliodbs(dot)com
and data management solutions (415) 565-7293
for law firms, small businesses fax 621-2533
and non-profit organizations. San Francisco

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Ligia Pimentel 2001-11-05 17:39:02 Left join error
Previous Message Josh Berkus 2001-11-05 16:49:09 Re: Porting Web application written in Oracle 8 PL/SQL