UPDATE vn.shelving SET isPrinted = TRUE WHERE LEFT (code, 2) IN ( SELECT DISTINCT LEFT(code,2) FROM vn.shelving WHERE isPrinted AND code REGEXP '^[A-Za-z]{2}[0-9]' ORDER BY code) AND code REGEXP '^[A-Za-z]{2}[0-9]'