Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: update, select and join in one statement ?

Re: update, select and join in one statement ?

From: Gene Hubert <ghubert_at_netpath.net>
Date: Sun, 29 Aug 1999 18:39:03 GMT
Message-ID: <F254BEE50F7EA5D2.654881AD6760D984.118D9BBC5B13F810@lp.airnews.net>


On Sat, 28 Aug 1999 23:48:32 +0200, "Guenter Gall" <gallg_at_t-online.de> wrote:

a small change lest table2 not contain a match for all rows in table1

update table1 t1
set t1.columnA=(select t2.columnA from table2 t2

                             where t1.columnB=t2.columnB)
WHERE EXISTS (select t2.columnA from table2 t2
                             where t1.columnB=t2.columnB);

Without the exists clause: Every row in table1 will be updated. Where there is no matching row in table2 you will get nulls written into table1 (or an error if the column does not allow nulls).

Gene Hubert
SkillsPoint.com
Morrisville, NC

>Hello Michael,
>
>try this:
>
>update table1 t1
>set t1.columnA=(select t2.columnA from table2 t2
> where t1.columnB=t2.columnB);
>
>Guenter Gall
>gallg_at_t-online.de
>
>
>Michael Keppler <Michael.Keppler_at_bigfoot.com> schrieb in im Newsbeitrag:
>7q9e6p$1h7_at_TGZ3...
>> Hello everybody !
>>
>> I try to build a statement like this:
>>
>> update table1
>> set table1.columnA=table2.columnA
>> where table1.columnB=table2.columnB
>>
>> Is something like this possible? I just don't get it right.
>> What I want is to "copy" the information of table2.columnA into
>> table1.columnA, but only if there is a join on the columns B possible
>> for the row that is to be updated.
>>
>> --
>> Michael Keppler, MCSE
>> IT logic GbR
>> Michael.Keppler_at_gmx.de
>>
>>
>
>
Received on Sun Aug 29 1999 - 13:39:03 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US