Copy a column from a given table to another column from another table

Asked

Viewed 80 times

-1

I’m trying to do the update below, only I’m having difficulty. I’m grateful for the help!!

UPDATE pctabpr set pctabpr.ptabela = (SELECT ptabela 
                                      FROM pcembalagem 
                                      WHERE pcembalagem.codprod = pctabpr.codprod);

What is wrong?

  • 1

    And what is your difficulty?

  • I don’t know if my update is correct is giving error when processing

  • What error? Add more details about the problem.

  • You need to give more accurate information about which error, the message, the ORA-XXXX error, etc. Anyway, looking at your update, if the subselect brings more than one value will give error, have you checked it? Also, you omitted in your example or your UPDATE is out of WHERE?

  • In order for this UPDATE to work the SELECT in question must return one and only one line, this may be the problem.

1 answer

1

As Motta said in the comment, there’s probably more than 1 entry coming in your subquery.

I believe that with JOIN you would solve this case:

UPDATE pctabpr 
SET ptabela = E.ptabela
FROM pctabpr A
INNER JOIN pcembalagem E ON E.codprod = A.codprod

Browser other questions tagged

You are not signed in. Login or sign up in order to post.