¿Cómo soluciono este error? No puede especificar la tabla de destino mi tabla para actualizar en la cláusula FROM

I'm struggling to convert my select query into a update query, it has aliases..

Update pads set RemoveMeDate = '1999-01-01 00:00:00' where padid in (
SELECT old_table.padid
FROM `jules-fix-reasons`.`pads` AS old_table
JOIN `jules`.`pads` AS new_table ON old_table.padid = new_table.`PadID`
WHERE new_table.RemoveMeDate <> '2001-01-01 00:00:00'
AND old_table.RemoveMeDate = '2001-01-01 00:00:00')

I've tried removing the aliases, but that doesn't help :(

EDIT - Richard, screen shot texto alternativo

preguntado el 09 de enero de 11 a las 09:01

Yeah I saw that it didn't work for me -

1 Respuestas

Update pads 
set RemoveMeDate = '1999-01-01 00:00:00' 
where padid in (SELECT padid FROM 
                ( SELECT old_table.padid 
                 FROM `jules-fix-reasons`.`pads` AS old_table JOIN 
                      `jules`.`pads` AS new_table ON old_table.padid = new_table.PadID
                 WHERE new_table.RemoveMeDate <> '2001-01-01 00:00:00' AND old_table.RemoveMeDate = '2001-01-01 00:00:00') a)

Respondido el 09 de enero de 11 a las 13:01

That didn't work, even with the extra bracket. Did you miss something after a ? - Jules

Ooops, try that. Edited in place. - richard

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''jules-fix-reasons'.'pads' AS old_table JOIN 'jules'.'pads' AS new_table ON old_' at line 1 - Jules

Try that. Edited in place again. I don't have your tables, etc. so I can't check all the syntax... - richard

A is the alias for the subquery within the subquery I added. Basically I just wrapped your subquery in another subquery. It's a workaround for the way MySQL translates the SQL for update statements with subqueries. - richard

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.