0

I have 2 tables in an oracle 12c database and i want to update from 1 table to the next.

Table 1 (EMBLEMTEMPLATE et):
et.emblemtemplate_id, et.customer_id, et.code

Table 2 (PRODUCTLISTPERCUSTOMER):
plpc.productlistpercustomer_id, plpc.customer_id, plpc.emblemtemplate_id,

What i am trying to do:

  1. Check with all the plpc.productlistpercustomer if there is a plpc.emblemtemplate_id filled, if not this need to be updated.
  2. plpc.emblemtemplate_id needs to be updated with et.emblemtemplate_id where et.code = "999991"
  3. The tables must be joined on CUSTOMER_ID

i created a select:

select plpc.customer_id,
  plpc.productlistpercustomer_id,
  plpc.emblemtemplate_id,
  et.customer_id,
  et.emblemtemplate_id,
  et.code
  from productlistpercustomer plpc
  inner join emblemtemplate et
  on et.customer_id = plpc.customer_id
  where et.code = '999991'

Can somebody help me to translate this to a sql update script?

Thanks!

Visual of what i want to do

2 Answers 2

1

You may try using an update with a correlated subquery:

UPDATE
    productlistpercustomer plpc
SET
    emblemtemplate_id = (SELECT et.emblemtemplate_id
                         FROM emblemtemplate et
                         WHERE et.customer_id = plpc.customer_id AND
                               et.code = '999991')
WHERE
    emblemtemplate_id IS NULL;
Sign up to request clarification or add additional context in comments.

1 Comment

This was perfect!
0

How about merge?

MERGE INTO productlistpercustomer p
     USING emblemtemplate e
        ON (e.customer_id = p.customer_id)
WHEN MATCHED
THEN
   UPDATE SET p.emblemtemplate_id = p.emblemtemplate_id
           WHERE     e.code = 999991
                 AND p.emblemtemplate_id IS NULL;

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.