5

I would like to update multiple columns in one table based on values in another.

I think I know how to write an update statement in T-SQL that does what I want (haven't tested the below). Problem is I'm trying to translate this for an Oracle database. Does anyone know how to do the following in Oracle:

UPDATE oldauth SET
  AUTHUNIQUENAME=newauth.AUTHUNIQUENAME
  DESCRIPTION=newauth.DESCRIPTION
  MAPPINGAUTHNAME=newauth.MAPPINGAUTHNAME
FROM
 (SELECT * FROM USERS1 WHERE AUTHSOURCEID=100) oldauth
LEFT JOIN
 (SELECT * FROM USERS2 WHERE AUTHSOURCEID=200) newauth
ON 
oldauth.AUTHUSERNAME=newauth.AUTHUSERNAME;

1 Answer 1

3
MERGE
INTO   (
       SELECT  *
       FROM    users1
       WHERE   AUTHSOURCEID=100
       ) oldauth
USING  (
       SELECT  *
       FROM    users2
       WHERE   AUTHSOURCEID=200
       ) newauth
ON     oldauth.AUTHUSERNAME=newauth.AUTHUSERNAME
WHEN MATCHED THEN
UPDATE
SET    AUTHUNIQUENAME=newauth.AUTHUNIQUENAME,
       DESCRIPTION=newauth.DESCRIPTION,
       MAPPINGAUTHNAME=newauth.MAPPINGAUTHNAME
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.