UPDATE vn.ticket t JOIN ( SELECT id, ticketFk__ FROM vn.cmr WHERE ticketFk__ ) sub ON sub.ticketFk__ = t.id SET cmrFk = sub.id;