Avatar of brgdotnet
brgdotnet
Flag for United States of America asked on

Update based upon a select

I need to update Table_1 based upon a select of data from two other tables "ROLD" and "PP";
My Oracle Sql is not correct. Can someone tell me how to modify the query below so that it is syntactically correct?


UPDATE Table_1
 SET
 (Table_1.Id = ROLD.Id,
  Table_1.FName = ROLD.FName,
  Table_1.LName = ROLD.LNAME,
  Table_1.PurchasePrice = PP.PurchasePrice
) =
 (FROM ROLD,PP WHERE ROLD.ID = PP.ID);
Oracle Database

Avatar of undefined
Last Comment
slightwv (䄆 Netminder)

8/22/2022 - Mon
Pawan Kumar

How Table_1 and the ( SELECT of ROLD,PP ) are related.. how they are joined.
SOLUTION
Pawan Kumar

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
slightwv (䄆 Netminder)

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
ASKER CERTIFIED SOLUTION
Mark Geerlings

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
slightwv (䄆 Netminder)

>>instead of the merge syntax, you can use this syntax:

Using my test case above, small syntax error with "SET UPDATE Table_1"

>>or a sub-query of ROLD (and/or PP) that will return only the matching rows.

That is why I didn't post that syntax.  It would normally be another query against the base table.  I'm not sure it is worth the extra table access but I suppose it might be better in certain situations.

Execution plans would likely decide it.
Pawan Kumar

>>I agree that MERGE is probably what you want here. Pawan's code has a couple of errors in it.

There are no errors in my code. Slightwv has just used my code(only 1 change Table_1 -> tab1) with an added condition ON (T.id = l.id) and removed this from the update statement. It may or may not be correct so let the author confirm that. The joining condition was not clear - Read my first comment - "How Table_1 and the ( SELECT of ROLD,PP ) are related.. how they are joined.".
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
slightwv (䄆 Netminder)

>>There are no errors in my code.
There are more changes than just the table name.  Please run my test case using your SQL.  It will generate syntax errors.