Yogesh Yogesh - 2 months ago 12
SQL Question

Updating a table in oracle with were conditions from other table

I want to update a record for a table and based on foreign key from other table..

Update table1 t1
Inner join table2 t2 on t2.id = t1. Id
Set t1. Name ='abc'
Where t2. User ='xyz';

Answer

That syntax is not valid in Oracle use MERGE

MERGE INTO table2 trg 
using table1 src 
ON (trg.id = src.id 
   AND trg.user = 'xyz') 
WHEN matched THEN 
  UPDATE SET trg.NAME = 'abc';