-1

there are two tables named TEST1 and TEST2 each has two columns, ID and NAME as below.

TEST1
ID  NAME
1   BOB
2   MIKE
3   TOM
4   TAMA

TEST2
    ID  NAME
    1   RAMIN
    2   RAHIM
    3   RONA
    4   ZAK
    6   ZENO
    7   YOURA
    8   SONE

i want to update table TEST1 (NAME) Column with TEST2 (NAME) Column values if ID in table TEST1 matched with ID in table TEST2.

running below query will result this error msg "ORA-00933: SQL command not properly ended"

UPDATE tbl_test1 
SET    tbl_test1.NAME = tbl_test2.NAME 
FROM   tbl_test1 
   INNER JOIN tbl_test2 
           ON tbl_test1.id = tbl_test2.id 
rsjaffe
  • 5,600
  • 7
  • 27
  • 39
Mellad Qarizada
  • 129
  • 1
  • 5
  • 16
  • hi Mureinik i searched stackoverflow but can not find it, can you plz send me the link where does it is answered, coz i checked found a bit different that could not solve my problem – Mellad Qarizada Jan 29 '17 at 08:20
  • This brief article in the documentation shows the proper syntax for updating through a join in Oracle, and the most common error you may run into (when you use the correct syntax), the reason for it, and how to fix it: http://stackoverflow.com/documentation/oracle/8061/update-with-joins#t=201701291448187158868 –  Jan 29 '17 at 14:48

1 Answers1

0

Best to use MERGE here:

merge into tbl_test1 t
using tbl_test2 t2 on (t.id = t2.id)
when matched then
  update set t.name = t2.name;
Gurwinder Singh
  • 38,557
  • 6
  • 51
  • 76