Update with Join MYSQL

Asked

Viewed 77 times

3

I have a table with customer data, with the 'broker name' and 'codbroker' fields. I need to update the codbroker from the data of my user table, where I have 'name' and 'codusuario'. So that it’s something like codcorretor=codusuario where nomecorretor=nome

I tried to do it this way but it didn’t happen:

update clientes set cli.codcorretor=us.codusuario
inner join usuario us on cli.nomecorretor=us.nome
where us.codusuario in (select codusuario from usuario);

Can someone help me ?

Thank you.

1 answer

3


Us UPDATEs with JOIN, the JOINshould come before the SET. Soon, your query would look like this::

update clientes
inner join usuario us on cli.nomecorretor = us.nome
set cli.codcorretor = us.codusuario
where us.codusuario in (select codusuario from usuario);
  • It worked, I just had to change the encoding to utf8_general_ci and it worked! Thank you very much !

Browser other questions tagged

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