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

Home -> Community -> Usenet -> c.d.o.misc -> Re: Update a Table from a Second Table

Re: Update a Table from a Second Table

From: Daniel Morgan <damorgan_at_exxesolutions.com>
Date: Fri, 27 Jun 2003 16:16:02 -0700
Message-ID: <3EFCD032.C479325B@exxesolutions.com>


Greg wrote:

> This is an easy way to update a table from a second table in Sql
> Server.
>
> update table1
> set table1.col2 = table2.col2
> from table1, table2
> where table1.keycol = table2.keycol
>
> I know you can do something like this in Oracle:
>
> update table1 a
> set table1.col2 = (select col2 from table2 where table2.keycol =
> a.keycol)
>
> but that example will update every row in table1, not just the ones
> that match the rows in table2.
>
> The sql server version not only gets the values it needs from the
> second table, it also limits the rows updated to those the matching
> rows in table2.
>
> Is there an easy way to do this in Oracle?
>
> thanks much

It never fails to amaze me that people coming to Oracle from SQL Server think there is something they can do in SQL Server that possibly can't be done in Oracle or that somehow, as in this case, a minor syntax change, is an onerous burden.

You will find numerous examples if you go to http://tahiti.oracle.com or open any Oracle book.

And once you learn them they will be extremely simple.

--
Daniel Morgan
http://www.outreach.washington.edu/extinfo/certprog/oad/oad_crs.asp
damorgan_at_x.washington.edu
(replace 'x' with a 'u' to reply)
Received on Fri Jun 27 2003 - 18:16:02 CDT

Original text of this message

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