CREATE OR REPLACE TRIGGER Org_Delete_Trigger
    AFTER DELETE ON Organization
    REFERENCING OLD AS OLD
    FOR EACH ROW
BEGIN
--     delete link
--     from OrgClosure p, OrgClosure link, OrgClosure c
--     where p.parentId = link.parentId and c.childId = link.childId
--     and p.childId = OLD.parentOrgId and c.parentId = OLD.id;

    delete from OrgClosure as O where exists (
        SELECT 1
        FROM OrgClosure p, OrgClosure c
        WHERE p.parentId = O.parentId AND c.childId = O.childId
              AND p.childId = OLD.parentOrgId
              AND c.parentId = OLD.id
    );
END
