UPDATE t_transaction tu
JOIN (
SELECT code, MAX(flag) AS flag
FROM t_transaction
GROUP BY
code
) t
ON tu.code = t.code
SET tu.flag = t.flag
UPDATE t_transaction tu
JOIN (
SELECT code, MAX(flag) AS flag
FROM t_transaction
GROUP BY
code
) t
ON tu.code = t.code
SET tu.flag = t.flag