user3503758
user3503758

Reputation: 77

Using Merge in Oracle SQL

Is there any possible way we can use join in merge statement?

MERGE INTO TABLE1 T
   USING TABLE2
   ON .....
   WHEN MATCHED THEN .....
   WHEN NOT MATCHED THEN INSERT (X,Y,Z1) VALUES (X,Y,Z1);

X and Y belong TABLE2 and no problem with merging, but I also want to insert Z1 from another TABLE3, when merging into TABLE1.

I am trying to join TABLE3 but it's not allowed in Merging syntax.

Is there any way to do so?

Upvotes: 1

Views: 415

Answers (1)

Dave Costa
Dave Costa

Reputation: 48131

The USING clause can take a subquery as its argument. It sounds like you want something like this:

MERGE INTO table1 t
USING (
  ... subquery joining TABLE2 and TABLE3 ...
) f
ON f.something = t.something
...

Upvotes: 1

Related Questions