我想更新表的记录并基于其他表中的外键..
Update table1 t1
Inner join table2 t2 on t2.id = t1. Id
Set t1. Name ='abc'
Where t2. User ='xyz';
答案 0 :(得分:1)
该语法在Oracle使用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';
答案 1 :(得分:1)
您也可以使用Exists
Update table1
Set Name ='abc'
Where exists (select 1
from table2 t2
where t2.id = table1.Id
and t2.User ='xyz');
答案 2 :(得分:1)
您可以使用此查询
MERGE INTO table1 t1
USING table2 t2
ON (t1.id = t2.id and t2.User='xyz')
WHEN MATCHED THEN
update
set t1.Name = 'abc';