Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.misc -> Re: Basic SQL question on UPDATE command
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 BortelReceived on Mon Mar 24 2003 - 14:33:34 CST