Update with self-join

烂漫一生 提交于 2019-12-01 07:36:57

Oracle does not support JOIN clause in UPDATE statements.

Use this:

MERGE
INTO    contactassociations ca1
USING   contactassociations ca2
ON      (
        ca1.contactid = ca2.contactid
        AND ca1.entitytable = 'EMPLOYER'
        AND  ca2.entitytable = 'CLIENT'
        )
WHEN MATCHED THEN
UPDATE
SET     parentid = ca2.id

I find the following style simpler to read, but you need to use an alias after the UPDATE key word, not the table name:

UPDATE ca1
SET    ca1.parentid = ca2.id
FROM contactassociations ca1
LEFT JOIN contactassociations ca2 ON (ca1.contactid = ca2.contactid)
WHERE ca1.entitytable = 'EMPLOYER' AND ca2.entitytable = 'CLIENT'
siripuram
-- Method #1
update emp set MANAGERNAME= mgr.EMPNAME
FROM SelfJoinTable emp , SelfJoinTable mgr where emp.MANAGERID = mgr.EMPID

-- Method #2
update emp 
set  MANAGERNAME= mgr.EMPNAME  
FROM SelfJoinTable emp 
   LEFT OUTER JOIN SelfJoinTable mgr 
   ON emp.MANAGERID = mgr.EMPID

-- Method #3
update emp 
set  MANAGERNAME= mgr.EMPNAME  
FROM SelfJoinTable emp 
   JOIN SelfJoinTable mgr 
   ON emp.MANAGERID = mgr.EMPID

-- Method #4
update emp 
set  MANAGERNAME= mgr.EMPNAME 
 FROM SelfJoinTable emp 
   inner JOIN SelfJoinTable mgr 
   ON emp.MANAGERID = mgr.EMPID
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!