command($sql); // And delete any orphaned rows in the repeat table $sql = "DELETE FROM " . _tbl('repeat') . " WHERE id NOT IN (SELECT repeat_id FROM " . _tbl('entry') . ")"; $orphan_result = db()->command($sql); echo $result;