Updating With Subquery [message #20194] |
Mon, 06 May 2002 08:12 |
Sulaiman Gboyega N.
Messages: 17 Registered: April 2002
|
Junior Member |
|
|
Hi All,
I have this situation descirbed below but I don't know how to construct such query in ORACLE.
I have two tables;
TableA TableB
AField1 BField1
AField2 BField2
AField3 BField3
What I want to do is to use the value of TableA.AField1 to update the value of TableB.BField1 where TableA.AField2=Table2.BField2
Thanks for your help.
|
|
|
Re: Updating With Subquery [message #20201 is a reply to message #20194] |
Mon, 06 May 2002 12:02 |
Todd Barry
Messages: 4819 Registered: August 2001
|
Senior Member |
|
|
update b
set field1 = (select a.field1
from a
where a.field2 = b.field2)
where exists (select null
from a
where a.field2 = b.field2);
If there is always a matching row in a, then you do not need the WHERE clause. Also, there can only be a maximum of one matching row in tablea for a particular value of b.field2.
|
|
|
|