using UPDATE

From: Christian Rudow <Christian(dot)Rudow(at)thinx(dot)ch>
To: PostgreSQL SQL <pgsql-sql(at)postgreSQL(dot)org>
Subject: using UPDATE
Date: 1999-06-28 07:05:41
Message-ID: 37771EC5.6A9CD3D8@thinx.ch
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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 alternate 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 ?

ThanX
--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Christian Rudow E-Mail: Christian(dot)Rudow(at)thinx(dot)ch
ThinX networked business services Stahlrain 10, CH-5200 Brugg
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Browse pgsql-sql by date

  From Date Subject
Next Message Christian Rudow 1999-06-28 08:27:23 Using Update
Previous Message Hub.Org News Admin 1999-06-27 14:41:37