delete from `detareceiv` where idaccountcuscuota not in (select id from accountcuscuota) ; delete from receiv where id not in (select id from detareceiv) ;