From: Josh Berkus <josh@agliodbs.com>
To: o2@trustcommerce.com
To: pgsql-sql@postgresql.org
Subject: Re: Help with a complex Update
Date: Mon, 05 Nov 2001 08:57:10 -0800
Message-ID: <web-498968@davinci.ethosmedia.com> (raw)
In-Reply-To: <9rv960$1des$1@news.tht.net>
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@agliodbs.com
and data management solutions (415) 565-7293
for law firms, small businesses fax 621-2533
and non-profit organizations. San Francisco
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 using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: josh@agliodbs.com, o2@trustcommerce.com
Subject: Re: Help with a complex Update
In-Reply-To: <web-498968@davinci.ethosmedia.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