UPDATE vn.travel t JOIN(SELECT t.id travelFk, d.awbFk FROM vn.dua d JOIN vn.duaEntry de ON de.duaFk = d.id JOIN vn.`entry` e ON e.id = de.entryFk JOIN vn.travel t ON t.id = e.travelFk GROUP BY t.id )sub ON sub.travelFk = t.id SET t.awbFk = sub.awbFk;