Re: Help with a complex Update - Mailing list pgsql-sql

From Josh Berkus
Subject Re: Help with a complex Update
Date
Msg-id web-498968@davinci.ethosmedia.com
Whole thread Raw
In response to Help with a complex Update  (Orion <o2@trustcommerce.com>)
List 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
GROUPBY user_id) ma
 
WHERE user_info.user_id = ma.user_id;

-Josh 

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


pgsql-sql by date:

Previous
From: Janning Vygen
Date:
Subject: Design Tool for postgresql
Next
From: David Stanaway
Date:
Subject: Re: select from a dynamic table name