Home » SQL & PL/SQL » SQL & PL/SQL » Updating With Subquery
Updating With Subquery [message #20194] Mon, 06 May 2002 08:12 Go to next message
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 Go to previous messageGo to next message
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.
Re: Updating With Subquery [message #20233 is a reply to message #20194] Wed, 08 May 2002 07:47 Go to previous message
Sulaiman Gboyega N.
Messages: 17
Registered: April 2002
Junior Member
Hi,

Thanks it works!!

Regards,
Sulaiman.
Previous Topic: clob and microsoft provider
Next Topic: how often is recomended to use commit in a loop
Goto Forum:
  


Current Time: Tue Apr 23 15:23:45 CDT 2024