CREATE TEMPORARY TABLE tempficpec (PRIMARY KEY (id_cocabe)) SELECT id_cocabe,  soporte,  fecha FROM quartup1.cialdoco WHERE soporte='PC' + DELETE cialdocolin FROM quartup1.cialdocolin LEFT JOIN tempficpec ON cialdocolin.id_cocabe=tempficpec.id_cocabe WHERE cialdocolin.soporte='PC' AND tempficpec.fecha>='20160612' AND tempficpec.fecha<='20160712' + DELETE cialdoco FROM quartup1.cialdoco WHERE cialdoco.soporte='PC' AND cialdoco.fecha>='20160612' AND cialdoco.fecha<='20160712'