Update via value difference by id

-1

I'm trying to perform an update through this select, where I see the different data from the pen_cadastro table, but when trying to perform an update, it presents errors:

[MYSQL]

UPDATE:

begin transaction
UPDATE pen_cadastro as CADAS
left OUTER JOIN novosusuarios 
ON novosusuarios.id <> CADAS.id 
set
CADAS.id = novosusuarios.id
group by novosusuarios.id

SELECT (This is working):

SELECT novosusuarios.*
FROM pen_cadastro 
left OUTER JOIN novosusuarios
ON novosusuarios.id <> pen_cadastro.id 
group by novosusuarios.id

That is, I need to update according to the ID difference from one table to another, if there are no new UUs in the pen_cadastro table then it will insert the values in the set fields that I point to.

    
asked by anonymous 25.07.2017 / 16:37

1 answer

2

You have to use a reference from your table when you are wrapping more than one table, that is, using a join.

Try this.

update CADAS
set CADAS.id = novosusuarios.id
FROM pen_cadastro as CADAS
left OUTER JOIN novosusuarios as novosusuarios
ON novosusuarios.id <> CADAS.id 
group by novosusuarios.id
    
25.07.2017 / 16:48