SELECT CONCAT("UPDATE CONCLUSION_PROCESS SET CONCLUSION_PROCESS.KEY_LAST_VERSION = ", CONCLUSION_PROCESS_VERSION.ID_INTERNAL, " WHERE CONCLUSION_PROCESS.ID_INTERNAL = ", CONCLUSION_PROCESS_VERSION.KEY_CONCLUSION_PROCESS, ";") AS '' FROM CONCLUSION_PROCESS_VERSION GROUP BY CONCLUSION_PROCESS_VERSION.KEY_CONCLUSION_PROCESS HAVING MAX(CONCLUSION_PROCESS_VERSION.CREATION_DATE_TIME);