Update from same table

From: Jürgen Cappel <email(at)juergen-cappel(dot)de>
To: "pgsql-sql" <pgsql-sql(at)postgresql(dot)org>
Subject: Update from same table
Date: 2004-02-04 16:46:19
Message-ID: JEEKIPNAKJNCFLMOBKHGOEDKDCAA.email@juergen-cappel.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Hello,

I want to update columns in a table that match a fixed key
from the same column of the same table matching another fixed key.
There can be several tuples per key distinguished by a secondary id.
Tuples are unique with the combined keys. Maybe a query could look
something like this:

UPDATE a.mytable from b.mytable
SET a.mycolumn = b.mycolumn
WHERE a.firstid = some_key
AND b.firstid = some_other_key
AND a.secondaryid = b.secondaryid;

But it's a syntax error. I tried a subselect but i'm failing to connect
the subselect's 2nd ID with the update's 2nd ID. Any help ? Thanks,

Jürgen

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Josh Berkus 2004-02-04 17:28:08 Re: Update from same table
Previous Message daq 2004-02-04 07:43:00 Re: SQL query