Update with join MYSQL

2

I have a table with client data, with the fields 'name_name' and 'code_name'. I need to update the 'codcorretor' from the data of my user table, where I have 'name' and 'codusuario'. So that something like codcorretor=codusuario where nomecorretor=nome

I tried to do this but it did not roll:

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 anyone help me?

Thank you.

    
asked by anonymous 23.11.2015 / 12:37

1 answer

2

In% s with UPDATE , JOIN s must come before JOIN . So 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);
    
23.11.2015 / 12:40