CREATE TEMPORARY TABLE tempficalc (PRIMARY KEY (id_cocabe)) SELECT id_cocabe,  soporte,  fecha FROM quartup1.cialdoco WHERE soporte='AC' + DELETE cialdocolin FROM quartup1.cialdocolin LEFT JOIN tempficalc ON cialdocolin.id_cocabe=tempficalc.id_cocabe WHERE cialdocolin.soporte='AC' AND tempficalc.fecha>='21060101' AND tempficalc.fecha<='99991231' + DELETE cialdoco FROM quartup1.cialdoco WHERE cialdoco.soporte='AC' AND cialdoco.fecha>='21060101' AND cialdoco.fecha<='99991231'