que estoy tratando de hacer una consulta como esta:MySQL CANCELACIÓN de la subconsulta como condición
DELETE FROM term_hierarchy AS th
WHERE th.parent = 1015 AND th.tid IN (
SELECT DISTINCT(th1.tid)
FROM term_hierarchy AS th1
INNER JOIN term_hierarchy AS th2 ON (th1.tid = th2.tid AND th2.parent != 1015)
WHERE th1.parent = 1015
);
Como usted puede decir probablemente, quiero eliminar la relación de los padres a 1015 si el mismo TID tiene otros padres. Sin embargo, lo que me produce un error de sintaxis:
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 'AS th
WHERE th.parent = 1015 AND th.tid IN (
SELECT DISTINCT(th1.tid)
FROM ter' at line 1
He comprobado la documentación, y ejecutar la sub consulta por sí mismo, y todo se parece a la salida. ¿Alguien puede descubrir lo que está mal aquí?
Actualización: Como se explica a continuación, MySQL no permite que la tabla que está eliminando se use en una subconsulta para la condición.
** Atención **: Buena respuesta en la parte inferior http://stackoverflow.com/a/4471359/956397 simplemente agregue el alias de la tabla después de 'DELETE t FROM table t ...' – PiTheNumber