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: Basic SQL question on UPDATE command

Re: Basic SQL question on UPDATE command

From: Frank <fvanbortel_at_netscape.net>
Date: Mon, 24 Mar 2003 21:33:34 +0100
Message-ID: <3E7F6B9E.5020200@netscape.net>


Lee Butler wrote:
> Hi,
>
> I'm trying to use the UPDATE command to update a column in one table with
> values from another table. I can't find references to how this is done in
> Oracle. I have tried the following which seems to work on Microsoft but
> gives me an error with Oracle:

What error? ALWAYS state error codes, if you had them. What oracle? Depending on the version, answers might not work Hmmm... strike that, read as 'answers may work'.
>
> UPDATE titles
> SET ytd_sales = t.ytd_sales + s.qty
> FROM titles t, sales s
> WHERE t.title_id = s.title_id
>

You found out it isn't....
It is a correlated subquery; this should work (not tested!) UPDATE titles t1
SET ytd_sales = (

	select t.ytd_sales + s.qty
         FROM titles t2, sales s
         WHERE t2.title_id = s.title_id
         AND   t2.title_id = t1.title_id)

-- 
Regards, Frank van Bortel
Received on Mon Mar 24 2003 - 14:33:34 CST

Original text of this message

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