How to update recovering value from another table?

Asked

Viewed 50 times

1

I have a chart in my comic book called contas. Where I log all system accounts.

As soon as they get paid I perform a update changing her status. However, I send a single update to several accounts, as follows:

update contas
set status='0',
    valor_recebido='aqui preciso capturar o campo valor'
where id IN ($ids)

So far so good, but in the field valor_recebido I need to capture the value of the field valor from the same table conta.

Does anyone know if this is possible?

I perform a update and at the same time assign the value of a table field to another field?

  • 3

    It’s not just changing valor_recebido=seuCampo?

  • Seriously though it’s that simple, pqp didn’t know, vlw even

  • worked out here even vlw hahahahah

  • Glad I could help. : ). rsrs

  • put that as an answer there for me to mark as accepted

  • Marconcílio posted one, accepts his :)

Show 1 more comment

1 answer

2


If the field is of the same table and the same key, you only need to set the field with the value of the other column.

update contas
set status='0',
    valor_recebido= valor_dasuacoluna
where id IN ($ids)

Now if the field is another key (ID) different you will have to do a JOIN or sub select

   update contas
    set status='0',
        valor_recebido= (select valor_dasuacoluna from contas where  id = outroid)
    where id IN ($ids)
  • very good was it ;)

Browser other questions tagged

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