def removeDoubleTerreinKoppeling(cur):
    cmd1 = "DELETE FROM TERREINOBJECT_HUISNUMMER_RELATIES\n           WHERE  BEGINTIJD IS NULL OR BEGINTIJD > DATE('now', '-1 day')\n           AND EXISTS (\n                    SELECT t2.terreinobjectid , t2.huisnummerid , t2.begindatum\n                    FROM TERREINOBJECT_HUISNUMMER_RELATIES t2\n                    WHERE eindtijd IS NULL\n                    AND TERREINOBJECT_HUISNUMMER_RELATIES.terreinobjectid = t2.terreinobjectid\n                    AND TERREINOBJECT_HUISNUMMER_RELATIES.huisnummerid = t2.huisnummerid\n                    AND TERREINOBJECT_HUISNUMMER_RELATIES.begindatum = t2.begindatum\n\n                    GROUP BY  t2.terreinobjectid,  t2.huisnummerid,  t2.begindatum\n                    HAVING COUNT(*) > 1\n                    AND MAX(t2.ID) <> TERREINOBJECT_HUISNUMMER_RELATIES.ID\n            ); "
    cmd2 = "DELETE FROM TERREINOBJECT_HUISNUMMER_RELATIES\n            WHERE BEGINTIJD IS NULL OR BEGINTIJD > DATE('now', '-1 day')\n            AND EXISTS (\n                SELECT einddatum FROM HUISNUMMERS\n                WHERE\n                ID = TERREINOBJECT_HUISNUMMER_RELATIES.huisnummerid\n                AND IFNULL(einddatum, '9999-01-01') <\n                IFNULL(TERREINOBJECT_HUISNUMMER_RELATIES.einddatum, '9999-01-01')\n                );"
    cur.execute(cmd1)
    cur.execute(cmd2)
def removeDoubleTerreinKoppeling(cur):
    cmd1 = "DELETE FROM TERREINOBJECT_HUISNUMMER_RELATIES\n           WHERE  BEGINTIJD IS NULL OR BEGINTIJD > DATE('now', '-1 day')\n           AND EXISTS (\n                    SELECT t2.terreinobjectid , t2.huisnummerid , t2.begindatum\n                    FROM TERREINOBJECT_HUISNUMMER_RELATIES t2\n                    WHERE eindtijd IS NULL\n                    AND TERREINOBJECT_HUISNUMMER_RELATIES.terreinobjectid = t2.terreinobjectid\n                    AND TERREINOBJECT_HUISNUMMER_RELATIES.huisnummerid = t2.huisnummerid\n                    AND TERREINOBJECT_HUISNUMMER_RELATIES.begindatum = t2.begindatum\n\n                    GROUP BY  t2.terreinobjectid,  t2.huisnummerid,  t2.begindatum\n                    HAVING COUNT(*) > 1\n                    AND MAX(t2.ID) <> TERREINOBJECT_HUISNUMMER_RELATIES.ID\n            ); "
    cmd2 = "DELETE FROM TERREINOBJECT_HUISNUMMER_RELATIES\n            WHERE BEGINTIJD IS NULL OR BEGINTIJD > DATE('now', '-1 day')\n            AND EXISTS (\n                SELECT einddatum FROM HUISNUMMERS\n                WHERE\n                ID = TERREINOBJECT_HUISNUMMER_RELATIES.huisnummerid\n                AND IFNULL(einddatum, '9999-01-01') <\n                IFNULL(TERREINOBJECT_HUISNUMMER_RELATIES.einddatum, '9999-01-01')\n                );"
    cur.execute(cmd1)
    cur.execute(cmd2)