From: Christian Rudow <Christian.Rudow@thinx.ch>
To: PostgreSQL SQL <pgsql-sql@postgreSQL.org>
Subject: Using Update
Date: Mon, 28 Jun 1999 10:27:23 +0200
Message-ID: <377731EB.AACAEA8B@thinx.ch> (raw)
I have the following SQL understanding problem concerning UPDATE :
I have two tables I want to join over a new artificial key a_id.
The tables can already be joined over an existing foreign key.
select a.a_id from a,b
where a.custno = b.custno
=> selects about 1000 id's
b.a_id so far only holds NULL values and should be updated to hold the
correct foreign key references to a.a_id.
+-------------------+
| a |
|-------------------|
| a_id prim. key |0---+
| custno altern.key| |
+-------------------+ |
|
mc
+----------------+
| b |
+----------------+
| b_id prim.Key |
| a_id forgn.Key|
1 custno |
+----------------+
What i want to do is something like this :
------------------------------------------
update b
set b.a_id = a.a_id
where b.custno = a.custno;
or is that the right way to do it ? :
update b
set b.a_id = (select a.a_id
from a,b
where a.custno = b.custno)
where b.custno in (select a.custno from a);
I just seem to use the UPDATE not correctly, it cannot be parsed.
What is the correct solution to this ?
Can anyone help ?
I know that's a RTFM but I have no FM to R.
Is there a good SQL tutorial/reference accessible over the net ?
ThanX
--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Christian Rudow E-Mail: Christian.Rudow@thinx.ch
ThinX networked business services Stahlrain 10, CH-5200 Brugg
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-sql@postgresql.org
Cc: Christian.Rudow@thinx.ch
Subject: Re: Using Update
In-Reply-To: <377731EB.AACAEA8B@thinx.ch>
References: <377731EB.AACAEA8B@thinx.ch>
* 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