UPDATE APP_DELEGATION AS APPDEL INNER JOIN (SELECT APP_UID, MAX(DEL_INDEX) AS MAX_DEL_INDEX FROM APP_DELEGATION GROUP BY APP_UID) AS SUBSQL
       ON SUBSQL.APP_UID = APPDEL.APP_UID AND SUBSQL.MAX_DEL_INDEX = APPDEL.DEL_INDEX
SET    APPDEL.DEL_LAST_INDEX = 1