0
I have the following query:
update ivr_contatos,ivr_campanha set ivr_contatos.tentativas = 0 where ivr_contatos.status = 0 and ivr_contatos.tentativas >= ivr_campanha.qtdtentativas
the doubt is, if I can update the field attempts of the table ivr_contacts using as a premise the field status (ivr_contacts) and qtdtentativas (ivr_campaign)
Table structure:
The data I can’t get through because I don’t have it yet.
puts the structure of the tables, and an example of the data please
– Rovann Linhalis
@Rovannlinhalis added structure...
– Willian Lima
I don’t know if the postgree will accept, but normally I do it this way
update ivr_contatos
set ivr_contatos.tentativas = 0 
where ivr_contatos.status = 0 
 and ivr_contatos.tentativas >= (select qtdtentativas from ivr_campanha where id=ivr_contatos.campanha)
– Rodrigo K.B
@Rodrigok. B Thus, it of the relation error. : column "ivr_contacts" of relation "ivr_contacts" does not exist
– Willian Lima
Changing Rodrigo’s code a little bit:
update ivr_contatos set tentativas = 0 where status = 0 and tentativas >= (select x.qtdtentativas from ivr_campanha x where x.id=ivr_contatos.campanha)
– Rovann Linhalis
Rovann, just for understanding, x. represents an Alias for the right ivr_campaign table?
– Willian Lima
To answer your question to Rovann, yes. And to complement, regarding the mistake you wrote, just follow the guidance of the colleague, which will work.
– Rodrigo K.B
It worked as I wanted. I could post as an answer to mark it please?
– Willian Lima